網(wǎng)頁記住用戶名,就是我們經(jīng)常會用到的,登錄下面有一個復(fù)選框,可以設(shè)置用戶7天內(nèi)或1個月不需要登錄,只要你進(jìn)行本網(wǎng)站系統(tǒng)查詢cookie是否有相差用戶名與密碼如果是就把信息提取再到數(shù)據(jù)庫中查詢,如果cookie中的用戶名與密碼是一樣的就實(shí)現(xiàn)用戶自動登錄了,PHP實(shí)例代碼如下:
- <?php
- error_reporting(0);
- session_start();
- ?>
- <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
- <html xmlns="http://m.survivalescaperooms.com/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312" />
- <title>網(wǎng)頁登錄中實(shí)現(xiàn)記住用戶名和密碼的功能(完成自動登錄)</title>
- </head>
- <body>
- <?
- $uid = $_cookie['uid'];
- $pwd = $_cookie['uid'];
- if( $uid !='' && $pwd !='' )
- {
- //sql數(shù)據(jù)庫查詢驗(yàn)證
- $_session['uid'] ='abc';
- }
- if( $_session['uid'] )
- {
- echo '會員中心,發(fā)表文章,到http://m.survivalescaperooms.com去玩';
- }
- else
- {
- ?>
- <form id="form1" name="form1" method="post" action="">
- <p>
- <label for="uid"></label>
- <input type="text" name="uid" id="uid" />
- </p>
- <p>
- <label for="pwd"></label>
- <input type="text" name="pwd" id="pwd" />
- </p>
- <p>
- <input type="checkbox" name="checkbox" id="checkbox" value="7" />
- <label for="checkbox"></label>
- 一周內(nèi)不用登錄
- </p>
- <p>
- <input type="submit" name="button" id="button" value="登錄" />
- </p>
- <p> </p>
- </form>
- <?
- }
- ?>
- </body>
- </html>
- <?php
- if( $_post )
- {
- $info = $_post;
- if( $info['uid'] !='' && $info['pwd'] !='')
- {
- //sql查詢操作,用戶名與密碼到數(shù)據(jù)庫中驗(yàn)證
- if( intval($info['checkbox']) )
- {
- setcookie('uid',$info['uid'],time()+3600*24*7,'/','192.168.0.118');
- setcookie('pwd',$info['pwd'],time()+3600*24*7,'/','192.168.0.118');
- }
- $_session['uid'] ==$info['uid'];
- }
- }
- ?>
新聞熱點(diǎn)
疑難解答