paruby Posted January 13, 2008 Share Posted January 13, 2008 Hello all - I am looking for advice and help w/ Sessions. First, what I am trying to do - have a user login, and set their username as a session variable. I am trying to avoid using cookies, as my users may not have cookies enabled, and also try to get away w/out sending variables via the URL. My pages are as follows: index.php: <FORM ACTION="login.php" METHOD="POST"> <table align="center"> <tr> <td>Name:</td> <td><input type="text" align="LEFT" name="txtName" size="20"></td> </tr> <tr> <td>Email:</td> <td><input type="text" align="LEFT" name="txtEmail" size="20"></td> </tr> <tr> <td colspan = "2"><input type="Submit" value="Submit" name="CmdLogin"></td> </tr> </table> </form> login.php: <?php if (isset($_POST['CmdLogin'])) { $thisEMail = $_POST['txtEMail']; $thisName = $_POST['txtName']; session_start(); $_SESSION[username] = $thisName; echo "Session Username = [".$_SESSION[username]."]<br>"; echo "<a href='eventList.php'>Events List</a>"; } ?> On the above page, the value prints out... eventList.php: <?php echo "Session Username = [".$_SESSION[username]."]<br>"; ?> On th above page, the value does not print. If I print out the "session_id" on the login.php page, and send it via url, it then also prints on the eventList.php page, but the original $_SESSION[username] value still does not... My session_globals value in my ini is set to false. What am I missing, and can I do this without sending variables via the URL? I have also read that some session components will be removed for PHP 6. I am using PHP 5. Thanx! Quote Link to comment https://forums.phpfreaks.com/topic/85768-session-basics-and-help/ Share on other sites More sharing options...
p2grace Posted January 13, 2008 Share Posted January 13, 2008 Do you have session_start() at the top of every page? Quote Link to comment https://forums.phpfreaks.com/topic/85768-session-basics-and-help/#findComment-437755 Share on other sites More sharing options...
paruby Posted January 13, 2008 Author Share Posted January 13, 2008 I only have the "session_start() on the login.php page, not on the eventList.php. If I had it on that page, wouldn't it start a new session, new id, and clear the username variable I want to keep?? Quote Link to comment https://forums.phpfreaks.com/topic/85768-session-basics-and-help/#findComment-437762 Share on other sites More sharing options...
revraz Posted January 13, 2008 Share Posted January 13, 2008 You need session_start(); at the top of every page that you want to use sessions on. Read the PHP manual for how it functions, and you will see that if there is already an existing session, it will use that one instead of creating a new one. Quote Link to comment https://forums.phpfreaks.com/topic/85768-session-basics-and-help/#findComment-437765 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.