1. 程式人生 > 實用技巧 >009迴文數

009迴文數

<?php

//使用session

//設定session
// session_start();
// $_SESSION['a'] = 'admin';


//設定cookie,如果有cookie,說明使用者已經登陸或者cookie在過期時間內,可以進行頁面跳轉,直接跳轉到首頁
if($_COOKIE){
    header('location:shouye.php');
}

if($_POST){
    $uname = trim($_POST['uname']);
    $pwd = md5($_POST['pwd']);
    if($uname == 'zhangsan' && $pwd == md5('123456')){
        //設定cookie值
        setcookie('admin','admin',time()+3600);
        //跳轉頁面
        header('location:shouye.php');
    }else{
        echo '賬號或密碼錯誤';
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" method="post">
        使用者名稱:<input type="text" name="uname" id="">
        密碼:<input type="password" name="pwd" id="">
        <input type="submit" value="提交">
    </form>
</body>
</html>
<?php
//session
// session_start();
// var_dump($_SESSION);


//判斷cookie值
/*
如果沒有cookie值,則說明使用者沒有登陸,直接跳轉到登陸頁面
*/
if(!$_COOKIE){
    //跳轉頁面
    header('loaction:login1.php');
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    歡迎登陸
</body>
</html>