Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用session_从Laravel开始,或者跨php文件使用Laravel会话_Php_Laravel_Laravel 5_Laravel 5.2 - Fatal编程技术网

使用session_从Laravel开始,或者跨php文件使用Laravel会话

使用session_从Laravel开始,或者跨php文件使用Laravel会话,php,laravel,laravel-5,laravel-5.2,Php,Laravel,Laravel 5,Laravel 5.2,我正在使用Laravel应用程序,在我的一个自定义页面上,我有以下内容: index1.php: require_once __DIR__ . '/../../../vanguard/extra/auth.php'; $request->session()->forget('token1'); $request->session()->put('token1', $generate_token1); $request->session()->keep(['t

我正在使用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()代码。

而不是制作一个自定义页面来制作一个
定义具有命名空间的类 并且在任何页面内的任何页面中使用它,如下面所示。 以下是我的步骤:

app/library/myFunctions.php的内容如下:

<?php namespace App\library {
    class myFunctions {
        public function is_ok() {
            return 'myFunction is OK';
        }
    }
}
?>
在app\Http\Controllers\HomeController.php的公共索引()中,我添加了:


返回视图(“测试”)

为什么要在没有控制器的情况下使用它?因为我不确定如何使用。删除
$request
并仅使用
会话()
仍然不起作用。没有错误,我不太理解拉雷维尔。有什么方法可以使用自定义页面吗?这就是为什么我会回答它,这样你就可以模仿每一步,完成你想要的。
<?php
  $FmyFunctions1 = new myFunctions;
  $is_ok = ($FmyFunctions1->is_ok());
?>
"files": [
    "app/library/myFunctions.php"
],