Ok i am creating a middle ages online text based game i know the basic sessions but i want to know a way i can keep my user logged in till they close there browser does anyone know how i could do this with some sample code and an explanation?
Hi, Use php sessions, something like this would work <?php session_start(); $valid_user = $_POST['valid_user']; session_register('valid_user'); ?> This loads the user variable into a session, all you need to now is vaildate that user on each page they visit. So every page might have something like: <? session_start(); $valid_user = $_SESSION['valid_user']; if ( empty( $valid_user ) ) { //user not validated, goto login page. } else { //user valid, continue script } The process above registers $valid_user into a session, however, for more secure pratices you could verify the register variable with a mysql database. By no means an expert but this should do what you need.
You have to use simple session variable. A session variable expires when you close the browser. Cookies are created on timely basis so you cannot remove a cookie when browser closes.
That's not true. The session variable will expire when they leave the page UNLESS every page has session_start(); declared at the start. If that code doesn't exist, then the session will end after the leave the current page, not just when they close the browser.