php使用者登入與登出(cookie)

來源:互聯網
上載者:User

標籤:

登入介面

<?php    header(‘Content-type:text/html;charset=utf-8‘);       if(isset($_COOKIE[‘username‘]) && $_COOKIE[‘username‘]===‘zeng‘){        exit(‘您已經登入了,請不要重新登入‘);    }    if(isset($_POST[‘submit‘])){        if(isset($_POST[‘username‘]) && isset($_POST[‘password‘]) && $_POST[‘username‘]==‘zengguanling‘ && $_POST[‘password‘]==‘123456‘ ){            if(setcookie(‘username‘,$_POST[‘username‘],  time()+3600)){                header(‘location:skip.php?url=index.php&info=登入成功!3秒後跳轉到首面‘);            }  else {                echo ‘cookies設定失敗‘;            }        }  else {            header(‘location:skip.php?url=login.php&info=對不起,使用者名稱活密碼填寫錯誤!3秒後跳轉到登入頁面‘);        }    }?><!DOCTYPE html><html lang="zh-CN">    <head>        <meta charset="utf-8">        <title>請登入</title>    </head>    <body>        <form method="post" action="">            姓名:<input type="text" name="username" />            密碼:<input type="password" name="password"/>            <input type="submit" name="submit" value="登入"/>        </form>    </body></html>

跳轉處理頁面skip.php

<?php    if(!isset($_GET[‘url‘]) || !isset($_GET[‘info‘])){        exit();    }?><!DOCTYPE html><html>    <head>        <meta charset="utf-8">        <meta http-equiv="refresh" content="3,URL=<?php echo $_GET[‘url‘] ?>"/>        <title>正在跳轉中...</title>    </head>    <body>        <div><?php echo $_GET[‘info‘] ?></div>    </body></html>

登入首頁index.php

<?php    header(‘Content-type:text/html;charset=utf-8‘);        if(isset($_COOKIE[‘username‘]) && $_COOKIE[‘username‘]===‘zeng‘){        echo "您好!{$_COOKIE[‘username‘]},歡迎回來!";        echo "<a href=‘logout.php‘>登出</a>";    }  else {        echo "<a href=‘login.php‘>請登入</a>";    }?>

登出處理介面logout.php

<?php    header(‘Content-type:text/html;charset=utf-8‘);    if(isset($_COOKIE[‘username‘]) && $_COOKIE[‘username‘]===‘zeng‘){        if(setcookie(‘username‘,$_POST[‘username‘],time()-3600)){            header(‘location:skip.php?url=index.php&info=登出成功,正在跳轉!‘);        }else{            header(‘location:skip.php?url=index.php&info=登出失敗,請稍後重試!‘);        }    }?>

 

php使用者登入與登出(cookie)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.