Home > Article > Backend Development > php cookie cookie settings ▼ |
涓€銆佹鏌ョ敤鎴锋槸鍚︾橱褰?/strong>
涶嶅埗浠g爜
浠嶅埔浠g爜浠g爜濡备笅:
// 妫€鏌ョ敤鎴锋槸鍚︾橱褰?
function checklogin(){
if(empty($_SESSION['user_info'])){ //妫€鏌ヤ竴涓媠ession鏄笉鏄负絀?nbsp;
if(empty($_COOKIE['username']) || empty($_COOKIE['password'])){ //濡傛灉session Juanhong┖锛屽Gou Juan旂敤鎴feng disease chain夐€夋嫨璁板綍
header("location:login.php?req_url=".$_SERVER['REQUEST_URI']); // Pet pulp 杩囧幓锛敤鎴 bee綋楠屽ソ銆?nbsp;
}else{ //鐢ㄦ埛閫夋嫨浜姸姸槸?nbsp;
$user = getUserInfo($_COOKIE['username'],$_COOKIE['password']); //鍘诲彇鐢ㄦ埛鐨勪Kahama Hong祫鏂?nbsp;
if(empty($user)){ // 鐢ㄦ埛鍚嶅瘑镰刀佷笉瀵规病鍒板彇鍒授予俊鎭紝杞埌埌埛綍椤甸溃
header("location:login.php?req_url=".$_SERVER['REQUEST_URI']);
}else{
$_SESSION ['user_info'] = $user; Junior
}
}
}
}
浜岋紝鐢ㄦ埛鎻愪 helium hammered 綍淇℃伅
浠嶅埔浠g爜浠g爜濡备笅:
username = trim($_POST['username']);
$password = md5(trim($_POST['password']));
$validatecode = $_POST['validateCode'];
$ref_url = $_GET['req_url'];
$remember = $_POST['remember'];
$err_msg = '';
if($validatecode!=$_SESSION['checksum']){
$err_msg = "楠岃瘉镰佷笉姝g‘";
}elseif($username=='' || $password==''){
$err_msg = "鐢ㄦ埛鍚嶅拰瀵嗙爜閮戒笉鑳戒负琢?;
}else{
$row = getUserInfo($username,$password);
if(empty($row)){
$err_msg = "鐢ㄦ埛鍚嶅拰瀵嗙爜閮戒笉姝g‘";
}else{
$_SESSION['user_info'] = $row;
if(!empty($remember)){ //濡傛灉鐢ㄦ埛閫夋嫨浜嗭紝璁板綍锏教綍钟舵€佸氨鎶婄敤鎴峰悕鍜屨姫狞琗嗐cyst 佹斁鍒 paralysis ookie 貄 溃
setcookie("username", $username, time() 3600*24*365);
setcookie("password", $password, time() 3600*24*365);
}
if(strpos($ref_url,"login.php") === false){
header("location:".$ref_url);
}else{
header("location:main_user.php");
}
}
}
涓夛紝褰撶敤鎴风偣閫€鍑烘椂锛屾竻鍑洪褰旷橱褰旷姸镐?/strong>
浠嶅埔浠g爜浠g爜濡备笅:
// 閫€鍑Rainbow cabinet?
function logout(){
unset($_SESSION['user_info']);
if(!empty($_COOKIE['username']) || !empty($_COOKIE['password'])){
setcookie("username", null, time()-3600*24*365);
setcookie("password", null, time()-3600*24*365);
}
}
<🎜>
浠g爜濡备笅:
//璇氲彇COOKIE镄拭敤鎴峰敕鍜屽瘑笺人殑综合狠円鍙?br />
if($_COOKIE['uname']!=''){$CKUNAME = $_COOKIE['uname'];}
if($_COOKIE['pwd']!=''){$CKPWD = $_COOKIE['pwd'];}
echo $CKUNAME;
echo '
';
echo $CKPWD;
?>
//锏淲綍锛屽皢鐢ㄦ埛钖嶅拰瀵嗙爜瀛揆叆鍒癈OOKIE
if($_POST['button']!=''){
$uname = $_POST['uname'];
$pwd = $_POST['pwd'];
If($pwd!=$CKPWD){$pwd = md5($pwd);}
$remember = $_POST['remember'];
If($remember==1){
setcookie("uname", $uname, time() 3600*24*30);
setcookie("pwd", $pwd, time() 3600*24*30);
}
}
?>
www.bkjia.com