php - 在 Laravel 中使用 session_start 或在 php 文件中使用 Laravel 会话
问题描述
我正在使用 Laravel 应用程序,在我的一个自定义页面上,我有以下内容:
index1.php:
require_once __DIR__ . '/../../../vanguard/extra/auth.php';
$request->session()->forget('token1');
$request->session()->put('token1', $generate_token1);
$request->session()->keep(['token1']);
redirectTo('index2.php');
index2.php:
require_once __DIR__ . '/../../../vanguard/extra/auth.php';
$token1 = $request->session()->get('token1');
echo $token1;
似乎会话没有跨页面保存。如果我在一个文件上使用所有代码,它就可以工作。有任何想法吗?
我正在使用它,因为我似乎无法session_start();
与 Laravel 一起使用。
解决方案
而是制作一个自定义页面,让一个类
定义一个具有命名空间的类,
并在任何页面内的任何页面中使用它,如下所示。这是我的步骤:
app/library/myFunctions.php 的内容如下:
<?php namespace App\library {
class myFunctions {
public function is_ok() {
return 'myFunction is OK';
}
}
}
?>
在 resources/views/test.blade.php ,我添加了:
<?php
$FmyFunctions1 = new myFunctions;
$is_ok = ($FmyFunctions1->is_ok());
?>
然后在“autoload”中的composer.json:我添加了:
"files": [
"app/library/myFunctions.php"
],
在公共 index() 的 app\Http\Controllers\HomeController.php 中,我添加:
返回视图('测试');
推荐阅读
- javascript - ion-item-slider 按钮未正确显示
- prestashop - 警告:在第 103 行的 */prestashop/src/PrestaShopBundle/Translation/Loader/SqlTranslationLoader.php 中为 foreach() 提供的参数无效
- python - 错误:'应用函数时解包的值太多(预期为 2)
- numpy - 多标签分类:解码一个热向量
- javascript - 未能设置矩阵单元格值
- c++ - 归并排序的归并函数
- c - 为什么“任何 K 字节的原始对象的地址必须是 K 的倍数”?
- javascript - W3C 的向下菜单窃听
- android - Game Maker Studio 2:Android:NDK 中的错误:setup-app.mk
- javascript - 在 JavaScript 中,如何更改正则表达式以匹配所有非字母数字字符?