資源簡介
PHP 利用COOKIE驗證用戶登錄的例子,用戶名和密碼存于數據庫中,其中的數據庫操作不是該例子的重點,本例子適合PHP新手學習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>
/***本例子數據庫名稱為alex要操作的表為user,有3個字段分別為:
userID,userName和password。***********************/
//數據庫查詢函數
function?dbOperate($sql){
$server?=?“localhost“;
$dbUsername?=?“root“;
$dbPSW?=?“root“;
//
$link?=?mysql_connect($server?$dbUsername?$dbPSW);
if?(!$link)?{
????die(‘Could?not?connect:?‘?.?mysql_error());
}else{
//選擇數據庫
mysql_select_db(‘alex‘$link);
$result?=?mysql_query($sql);
mysql_close($link);
return?$result;
}
}
評論
共有 條評論