Use session in php to create sessionsession_start (); $ _ SESSION ['username'] = $ username ;? On the page to be verified, use // to verify whether session exists in username php.
Create a session on the logon page
session_start(); $_SESSION['username'] = $username;
? Use
// Verify sessionsession_start (); // check whether username exists in the session and whether the session expires if (! Isset ($ _ SESSION ["username"]) | time () <($ _ SESSION ['username'] + 1200) {echo "log on first
"; Echo 'Click here to log on!
'; Exit ;}
? Cancel session
Session_start ();/*** delete all session variables .. You can also delete them one by one using unset ($ _ SESSION [xxx. * ***/$ _ SESSION = array ();/*** delete sessin id. because the session is cookie-based by default, setcookie is used to delete the cookie containing the session id. * **/if (isset ($ _ COOKIE [session_name ()]) {setcookie (session_name (), '', time ()-42000 ,'/');} // Finally, the session is completely destroyed. session_destroy (); // jump to the login page Header ("HTTP/1.1 303 See Other"); Header ("Location: login.html ");
? Ps: session_start (); there cannot be any output before, and it must be added to the top of the page
Otherwise, the system reports the following :? Session_start () [function. session-start]: Cannot send session cache limiter-headers? Already sent?