PHP cookie的應用

來源:互聯網
上載者:User

標籤:

 <?php      //判斷是否提交表單     if(isset($_POST[‘dosubmit‘])){         //登陸資料庫      $pdo=new PDO("mysql:host=localhost;dbname=xsphp","root","root");                //查詢資料庫  PDO的預先處理      $stmt=$pdo->prepare("select id,username,allow_1,allow_2,allow_3 from user where username=? and password=?");         // 執行預先處理      $stmt->execute(array($_POST[‘username‘],md5($_POST[‘password‘])));         //如果查到了          if($stmt->rowCount() >0){             list($id,$username,$allow_1,$allow_2,$allow_3)=$stmt->fetch(PDO::FETCH_NUM);             //將值賦給變數              $time=time()*24*60*60;             //設定cookie時間              setcookie("uid",$id,$time,"/");             setcookie("username",$username,$time,"/");             setcookie("allow_1",$allow_1,$time,"/");             setcookie("allow_2",$allow_2,$time,"/");             setcookie("allow_3",$allow_3,$time,"/");              //設定一個登陸判斷             setcookie(‘isLogin‘,1,$time,"/");               header("Location:index.php");           }else{             echo "登陸失敗";            }      }  ?>  <!DOCTYPE html> <html lang="en"> <head>  <meta charset="UTF-8">  <title>Document</title>  <style type="text/css">   </style> </head> <body>      <h2 align="center">使用者登入</h2>   <form action="login.php" method="post" style="margin-left: 40%;">          username : <input type="text" name="username" value="">       <p></p>      password : <input type="password" name="password" value="">       <p></p>       <input type="submit" value="登陸" name="dosubmit">       </form> </body>       </html>

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.