在Laravel 4.2中,我宣布了一个会话:
session_start();
$code=rand(100000,999999);
$_SESSION["captcha"]=$code;
然后我想获取我存储的数据,并在Laravel控制器中使用它来检查用户是否在我在数据库中输入之前输入了正确的代码。
这是我的代码:
public function store2()
{
// i was trying to get the value
// session_start();
// $getsCapt = $_SESSION["captcha"];
$rules = array(
'username' => 'required|min:2|max:50|regex:/^[a-zA-Z0-9\-\s]+$/',
'description' => 'required|min:1|max:100|regex:/^[a-zA-Z0-9\-\s]+$/',
'usertype' => 'required|numeric'
);
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails())
{
return Redirect::to('createsu')
->withErrors($validator)
->withInput(Input::except('password'));
}
else
{
// store
$su = new SystUser;
$su->SystemUserTypeID = Input::get('usertype');
$su->SystemUserName = Input::get('username');
$su->SystemUserPassword = 'changeme';
$su->SystemUserDescription = Input::get('description');
$su->timestamps = false;
$su->save();
// redirect
Session::flash('message', 'Successfully created system user!');
return Redirect::to('createsu');
}
}
答案 0 :(得分:0)
在Laravel你不必明确地开始会议。
您可以执行以下操作:
在会话中设置
$captcha='whatever';
Session::put('captcha', $captcha);
从会话中获取
if(Session::has('captcha'){
$captcha = Session::get('captcha');
}