This article mainly introduces PHP session control, and analyzes PHP's related operating techniques for cookies and sessions in the form of examples. Friends in need can refer to it
The details are as follows:
About Test code for cookie and session:
<?php session_start(); define('u','a'); define('p','1'); if (isset($_GET['r']) && $_GET['r']== 1) { unset($_COOKIE['username']); unset($_COOKIE['password']); unset($_SESSION['valid_login']); } if (isset($_POST['username']) && isset($_POST['password'])) { $username = $_POST['username']; $password = $_POST['password']; if ($username == u && $password == p) { $_SESSION['valid_login'] = 1; setcookie('username', $username); setcookie('password', $password); } else { echo 'incorrect u or p'; } } ?> <?php if (isset($_SESSION['valid_login'])) { printf('welcom, %s', $_COOKIE['username']); } else { ?> <form action="" method="post"> <input type="text" name="username" value="" /> <input type="password" name="password" value="" /> <input type="submit" /> </form> <?php } ?> <br /> <a href="cookie_session.php" title="">refresh</a> <br /> <a href="cookie_session.php?r=1" title="">clear</a>
The above is the entire content of this article, I hope it will be helpful to everyone's learning.
Related recommendations:
php implements the message board function based on session control
##PHPSession controlDetailed explanation of cookies
The above is the detailed content of PHP session control example analysis. For more information, please follow other related articles on the PHP Chinese website!