Thursday, July 30, 2009

How do I transfer variables between pHp pages?

I need the username of a logged in person on multiple pages on my website. I have already destroyed the pHp session so that when the person exits the browser, the session will end. However, now I cannot figure out how to send the username to a different page, since it was already stored in a session. How do I send the variable between pages?

How do I transfer variables between pHp pages?
What you can do, if you do not use a session to pass information is to pass information as a query string on the url to send it from page to page





so if you want to go to as a link to the next page %26lt;a href="homepage.php"%26gt;homepage%26lt;/a%26gt;





put this in


%26lt;a href="homepage.php?userName=%26lt;?=$userName...





then on the following page use the $_GET['userName']; method and you will get the variable you passed.





if you are putting it in a form then just put a %26lt;input type="hidden" name="userName" value="%26lt;?=$userName?%26gt;"%26gt;
Reply:You are best to carry the session over froppm page to page and use $_SESSION variables, if you don't want to do this use the $_GET variables.
Reply:If its stored in a session, then you will have access to it through the $_SESSION array. You may need to call session_start() first, if you don't have your server configured to autostart sessions.


No comments:

Post a Comment