Fenhopi Posted June 14, 2010 Share Posted June 14, 2010 So I need to get a variable stored in one page so that I can use the info stored in it on another page. I tried using a form and retrieve the $_POST function, but that obviously only works when the form is posted, which I don't Need. Does anyone have an alternative solution? Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 14, 2010 Share Posted June 14, 2010 If the 2nd page is accessed directly after the first, such as with a link or a redirect. You can append the variable to the URL (e.g. somepage.php?foo=bar). But, if the pages are not accessed sequentially and/or the value needs to persist over time, then you need to save the value somewhere. The most common solution would be a database. But, if you don't have access to a database and your need is limited, you can simply write the value to a flat-file on your server. Then read it on the pages where you need to access it. Tutorial for file writing and reading: http://www.tizag.com/phpT/filewrite.php Quote Link to comment Share on other sites More sharing options...
Fenhopi Posted June 14, 2010 Author Share Posted June 14, 2010 But storing it in a database seems so pointless seeing as that's why I need it in the firstplace. I need to Store the user name in a variable so that I can use his I'd to retrieve the right picture with the other page. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 14, 2010 Share Posted June 14, 2010 But storing it in a database seems so pointless seeing as that's why I need it in the firstplace. I need to Store the user name in a variable so that I can use his I'd to retrieve the right picture with the other page. You are not making any sense. I'm guessing you have multiple pictures in the DB for each user? And you want to display the current user's picture to them? Then you will need to use either cookies or session variables after the user has logged in so you "know" who they are on subsequent page requests. Quote Link to comment Share on other sites More sharing options...
Fenhopi Posted June 14, 2010 Author Share Posted June 14, 2010 I already have a session that retrieves their user name on the page where I'm loading the picture to. And yes, their user name is stored with the picture they upload so that it's easier to retrieve for each individual user. However I don't want to call the session in the other page. It seems easier for me to just grab the variable already stored in the previous page. It must be some easy way to do that? Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 14, 2010 Share Posted June 14, 2010 I already have a session that retrieves their user name on the page where I'm loading the picture to. And yes, their user name is stored with the picture they upload so that it's easier to retrieve for each individual user. However I don't want to call the session in the other page. It seems easier for me to just grab the variable already stored in the previous page. It must be some easy way to do that? Um, no. That is the whole point of storing variables in sessions - so you can track user variables across the session for the user. When a new page request is made from the server the page doesn't have any knowledge of what pages were processed previously or the variables that were calculated in them. And, what is so difficult about using session_start() and calling the variable you want? Quote Link to comment 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.