資源簡介
PHP 利用COOKIE驗證用戶登錄的例子,用戶名和密碼存于數(shù)據(jù)庫中,其中的數(shù)據(jù)庫操作不是該例子的重點,本例子適合PHP新手學(xué)習(xí)COOKIE的工作原理和如何使用COOKIE。
代碼片段和文件信息
lns=“http://www.w3.org/1999/xhtml“>
ta?http-equiv=“Content-Type“?content=“text/html;?charset=gb2312“?/>
tle>用戶登錄實例 tle>
yle?type=“text/css“>
body{?font-size:12px;}
yle>
/***本例子數(shù)據(jù)庫名稱為alex要操作的表為user,有3個字段分別為:
userID,userName和password。***********************/
//數(shù)據(jù)庫查詢函數(shù)
function?dbOperate($sql){
$server?=?“l(fā)ocalhost“;
$dbUsername?=?“root“;
$dbPSW?=?“root“;
//
$link?=?mysql_connect($server?$dbUsername?$dbPSW);
if?(!$link)?{
????die(‘Could?not?connect:?‘?.?mysql_error());
}else{
//選擇數(shù)據(jù)庫
mysql_select_db(‘a(chǎn)lex‘$link);
$result?=?mysql_query($sql);
mysql_close($link);
return?$result;
}
}
評論
共有 條評論