로그인, 로그아웃 시 주로 쿠키를 설정합니다. 로그인 저장 및 안전 종료
1: 로그인 페이지에서 설정
//쿠키 값 설정
_setcookies($_rows['tg_username'], $_rows['tg_uniqid '] ,$_clean['time']);
_location(null,'index.php');
2단계: 쿠키 생성
<span>/*</span><span>* * _setcookies * @param unknown $_username * @param unknown $_uniqid </span><span>*/</span><span>function</span> _setcookies(<span>$_username</span>,<span>$_uniqid</span>,<span>$_time</span><span>){ </span><span>setcookie</span>('username',<span>$_username</span><span>); </span><span>setcookie</span>('uniqid',<span>$_uniqid</span><span>); </span><span>switch</span> (<span>$_time</span><span>) { </span><span>case</span> '0' : <span>//</span><span> 设置浏览器进程</span><span>setcookie</span> ( 'username', <span>$_username</span><span> ); </span><span>setcookie</span> ( 'uniqid', <span>$_uniqid</span><span> ); </span><span>break</span><span>; </span><span>case</span> '1' : <span>//</span><span> 一天的进程</span><span>setcookie</span> ( 'username', <span>$_username</span>, <span>$_time</span> () + 86400<span> ); </span><span>setcookie</span> ( 'uniqid', <span>$_uniqid</span>, <span>$_time</span> () + 86400<span> ); </span><span>break</span><span>; </span><span>case</span> '2' : <span>//</span><span> 一周的进程</span><span>setcookie</span> ( 'username', <span>$_username</span>, <span>$_time</span> () + 604800<span> ); </span><span>setcookie</span> ( 'uniqid', <span>$_uniqid</span>, <span>$_time</span> () + 604800<span> ); </span><span>break</span><span>; </span><span>case</span> '0' : <span>//</span><span> 一个月的进程</span><span>setcookie</span> ( 'username', <span>$_username</span>, <span>$_time</span> () + 2592000<span> ); </span><span>setcookie</span> ( 'uniqid', <span>$_uniqid</span>, <span>$_time</span> () + 2592000<span> ); </span><span>break</span><span>; } }</span>
세 번째 단계: 로그인 상태에
<span>//</span><span>登录的情况,就是防止登陆后通过在浏览器中直接连接再次登录</span><span>function</span><span> _login_state(){ </span><span>if</span> (!<span>isset</span>(<span>$_COOKIE</span>['username'<span>])) { _alert_back(</span>"登录状态无法就行本操作!"<span>); } }</span>
<span>//</span><span>删除cookies</span><span>function</span><span> _unsetcookies(){ </span><span>setcookie</span>('username','',<span>time</span>()-1<span>); </span><span>setcookie</span>('uniqid','',<span>time</span>()-1<span>); _session_destroy();</span><span>//</span><span>删除session</span> _location(<span>null</span>,'index.php'); <span>//</span><span>做跳转</span>}
을 설정합니다. 네 번째 단계는
<span>//</span><span>登录状态</span> _login_state();위 내용은 PHP 실습 프로젝트 노트의 COOKIES를 다양한 측면에서 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.