Jump to content

how do i get a variable stored on another page?


Fenhopi

Recommended Posts

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.