laravel5.6的session问题


问题1:

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
//引用对应的命名空间
use Gregwar\Captcha\CaptchaBuilder;
use Illuminate\Support\Facades\Session; 
//require_once 'org/captcha/Code.class.php';

class VerifyController extends Controller
{
    public function loadcaptcha(Request $request,$tmp)
    {
        //生成验证码图片的Builder对象,配置相应属性
        $builder = new CaptchaBuilder;
        //可以设置图片宽高及字体
        $builder->build($width = 100, $height = 40, $font = null);
        //获取验证码的内容
        $phrase = $builder->getPhrase();        
        //把内容存入session
        $request->session()->put('milkcaptcha', $phrase);
        //此处网上都是用flash方法,但是laravel5.6版本使用flash方法的话在session中无法获取到该值

        //生成图片
        header("Cache-Control: no-cache, must-revalidate");
        header('Content-Type: image/jpeg');
        $builder->output();

    }

    public function getcaptcha(Request $request)
    {
        $value = $request->session()->get('milkcaptcha');
        //$value = session::get('milkcaptcha');
        var_dump($value);

    }
  
}

strong text

看网上说路由中需添加'middleware' =>['web']来解决session问题,照做还是一样的问题,求大神帮忙解决下


Vote Vote Cancel Collect Collect Cancel

<< 上一篇: 中间件报错

>> 下一篇: 表单验证的$errors无法在session中获取