Moron Posted September 7, 2006 Share Posted September 7, 2006 Okay, on page 1 there is an HTML form where they enter Employee Number and Password.Page 2 - These values are used with $_POST. The database displays their First name Last Name, and Middle Initial, and other info.Page 3 - Is there a way to take and use First Name, Last Name, and Middle Initial from Page 2 that were NOT posted by a form? I want to pass these to page 3 using a session statement. Quote Link to comment https://forums.phpfreaks.com/topic/20003-use-a-session-variable-thats-not-from-_post-or-_get/ Share on other sites More sharing options...
obsidian Posted September 7, 2006 Share Posted September 7, 2006 well, you can definitely do what you're after with session variables. you'd want to have session_start() at the top of each page where you want the session variables to be available. for instance:[code]<?php// page 1 submits the info// page 2 retrieves it and assigns it to a session variable:$_SESSION['fName'] = $_POST['fName'];// page 3 retrieves and uses session variables:echo $_SESSION['fName'];?>[/code]that's really all there is to it, but you need to make sure to be starting the session for any page on which you need the variables. Quote Link to comment https://forums.phpfreaks.com/topic/20003-use-a-session-variable-thats-not-from-_post-or-_get/#findComment-87680 Share on other sites More sharing options...
Moron Posted September 7, 2006 Author Share Posted September 7, 2006 [quote author=obsidian link=topic=107220.msg429821#msg429821 date=1157632445]well, you can definitely do what you're after with session variables. you'd want to have session_start() at the top of each page where you want the session variables to be available. for instance:[code]<?php// page 1 submits the info// page 2 retrieves it and assigns it to a session variable:$_SESSION['fName'] = $_POST['fName'];// page 3 retrieves and uses session variables:echo $_SESSION['fName'];?>[/code]that's really all there is to it, but you need to make sure to be starting the session for any page on which you need the variables.[/quote]Not working.On Page 2, I have...[code]<?phpsession_start();$empcode = $_POST['empcode'];$_SESSION['empcode'] = $empcode;$lastname = $_POST['NAMEL'];$_SESSION['NAMEL'] = $lastname;?>[/code]On page 3 at the top, I have...[code]<?phpsession_start();$_SESSION['empcode'];$_SESSION['NAMEL'];?>[/code]Further down, I have....[code]$_SESSION['empcode'];$_SESSION['NAMEL'];echo "<CENTER>";echo "<font size=4 color=#000000 face=arial>";echo "<b>";echo $_SESSION['empcode'];echo $_SESSION['NAMEL'];echo "</b>";echo "</font>";[/code]It echoes empcode (Employee Number), but not NAMEL (Last Name). Quote Link to comment https://forums.phpfreaks.com/topic/20003-use-a-session-variable-thats-not-from-_post-or-_get/#findComment-87694 Share on other sites More sharing options...
ober Posted September 7, 2006 Share Posted September 7, 2006 Doing this doesn't do ANYTHING.<?phpsession_start();$_SESSION['empcode'];$_SESSION['NAMEL'];?>You only need session_start() at the top of the 3rd page. The session variables (if set previously) are already there.You can also take those 2 lines out further down.The rest should work if you've got all your capitalization correctly. Also, throw in "print_r($_SESSION);" to make sure all your variables are making it into the session. Quote Link to comment https://forums.phpfreaks.com/topic/20003-use-a-session-variable-thats-not-from-_post-or-_get/#findComment-87797 Share on other sites More sharing options...
shoombooltala Posted September 7, 2006 Share Posted September 7, 2006 i think what you need to do is the following:top of page2 you put:[code]<?phpsession_start();//in the middle of the page where the user gets authenticated and you get their first, middle and last name you would use this:$_Session['fname'] = $firstName; //where $firstname is the variable containing the name you got form the database of the user.$_Session['mname'] = $middleName; //where $middleNameis the variable containing the name you got form the database of the user.$_Session['lname'] = $lastName; //where $lastNameis the variable containing the name you got form the database of the user.?>[/code]then on top of page 3 also you put:[code]<?phpsession_start();//then you would retreive the values using this:echo $_Session['fname'];echo $_Session['mname'];echo $_Session['lname'];?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20003-use-a-session-variable-thats-not-from-_post-or-_get/#findComment-87806 Share on other sites More sharing options...
Jenk Posted September 7, 2006 Share Posted September 7, 2006 Page 1:[code]<?phpsession_start();$_SESSION['variable'] = 'Hello world!';header('Location: page2.php');?>[/code]Page2.php:[code]<?phpsession_start();echo $_SESSION['variable'];?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20003-use-a-session-variable-thats-not-from-_post-or-_get/#findComment-87808 Share on other sites More sharing options...
obsidian Posted September 7, 2006 Share Posted September 7, 2006 shoombootala, you [b]do not[/b] want to assign your session variables as you have shown. if you do that, the session variable 'fname' will actually hold the value "$firstName" and so on. you never want to try to assign variables from within single quotes.[code]<?php// change this idea:$_SESSION['fname'] = '$firstName';// to this:$_SESSION['fname'] = $firstName;// or this:$_SESSION['fname'] = "$firstName";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/20003-use-a-session-variable-thats-not-from-_post-or-_get/#findComment-87812 Share on other sites More sharing options...
shoombooltala Posted September 7, 2006 Share Posted September 7, 2006 [quote author=obsidian link=topic=107220.msg429958#msg429958 date=1157642800]shoombootala, you [b]do not[/b] want to assign your session variables as you have shown. if you do that, the session variable 'fname' will actually hold the value "$firstName" and so on. you never want to try to assign variables from within single quotes.[code]<?php// change this idea:$_SESSION['fname'] = '$firstName';// to this:$_SESSION['fname'] = $firstName;// or this:$_SESSION['fname'] = "$firstName";?>[/code][/quote]you are totally correct. I edited and fixed it now. Thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/20003-use-a-session-variable-thats-not-from-_post-or-_get/#findComment-87816 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.