首页 > 解决方案 > 在 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 一起使用。

标签: phplaravellaravel-5laravel-5.2

解决方案


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

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 中,我添加:

返回视图('测试');


推荐阅读