Hi I want to use sessions. first page is login.php--- form for login Second page logincheck.php---- I am storing user id as session variable. I can read the session variable in this page. But when I redirect to another page, the session variable is lost or I can not display it... Any help...
need to start the session on each of those pages.. if (!isset($_SESSION)) { session_start(); } If the session isn't started that will do it... Then you can access it like $_SESSION['foo'];
Hi I am sending the code. Nothing is displayed on the screen... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?php if (!isset($_SESSION)) { session_start(); } ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <? php echo $_SESSION['userid']; ?> </body> </html>
session_id($ID); // pass the id again (not the user id) session_start(); PHP: That should do that work
If you are using cookie-based sessions (which you probably are), you must call session_start() before anything is outputted to the browser. Anyway, PHP and HTML should stay separated for readability, only basic loops and echos should be in the main body of the HTML itself. Dan