Home >Backend Development >PHP Tutorial >Issues with identity verification through session_id
php code
<code>账号密码验证成功: session('uid',100); $sid=session_id(); $this->ajaxReturn(array("result"=>"1","sessionid"=>$sid)); </code>
The html page will save the session_id in a cookie named sid
<code> $.cookie('sid', response.data.sessionid);</code>
Verify php, sid (session_id) will be sent for each page request
<code> $sid=I('post.sid'); session_id($sid); $this->ajaxReturn(array("uid"=>session('uid'),"sid"=>"$sid")); </code>
Problem: The value of the session cannot be obtained. The value obtained is still null
But the sid is passed normally
php code
<code>账号密码验证成功: session('uid',100); $sid=session_id(); $this->ajaxReturn(array("result"=>"1","sessionid"=>$sid)); </code>
The html page will save the session_id in a cookie named sid
<code> $.cookie('sid', response.data.sessionid);</code>
Verify php, sid (session_id) will be sent for each page request
<code> $sid=I('post.sid'); session_id($sid); $this->ajaxReturn(array("uid"=>session('uid'),"sid"=>"$sid")); </code>
Problem: The value of the session cannot be obtained. The value obtained is still null
But the sid is passed normally
The session will automatically save the session ID on the client, and each request will also carry the session ID to the server. No additional processing is required. I don't know what the purpose of defining an additional sid cookie is.
In addition, cookies are scope-specific. Are the domains you requested the same twice?