wesmith4 Posted June 29, 2013 Share Posted June 29, 2013 I am using the script Login.php from the book and a version of strings.php to test viewing the session variables. But I can not show $_SESSION['user_id'] for some reason. Can anyone help me understand what I am doing wrong? --------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:la"en" lang="en"> session_start(); <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title> </head> <body> <?php # Script 1.6 - strings.php // Create the variables: $first_name = 'Willie'; $last_name = 'Smith'; $var = $_SESSION['user_id']; //Print the values: echo "<P>The names are $first_name and $last_name and $var.</p>"; ?> </body> </html> ----------------- I appreciate any help understanding the use of SESSIONS. Wes Smith Link to comment Share on other sites More sharing options...
margaux Posted June 29, 2013 Share Posted June 29, 2013 Your session_start needs to be the very first thing in strings.php and it needs to be between php tags. Assuming login.php creates $_SESSION['user_id'] and redirects the user to strings.php, try changing strings.php to start with <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ransitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:la"en" lang="en"> 1 Link to comment Share on other sites More sharing options...
Recommended Posts