Forum Moderators: coopster

Message Too Old, No Replies

Carrying (keeping) variable and forwarding it out

         

smallcompany

11:59 pm on Nov 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I did ask about this before, but not under such scenario:

I do have a working script that grabs a variable coming from a referrer URL. If I simply redirect it right away to my partner (no my own site except for redirection), it works fine.

Now I wonder about having that variable KEPT while people browse through my site, and forward it out once they click onto outgoing link.

From what I found, session or cookie could be options, not sure if they would be ONLY options, no argument, just curious.

Anyhow, I am aware of the fact that I have to grab my incoming variable first, so my existing code will be there. Then I need to either store it or carry around while user browses through the site, just so I have it "remembered" so I can forward it out.

My vision is that I would:

    Start a session
    Grab variable and keep it during session
    Script that maintains outgoing links will grab it and forward it further

Three questions:

    How would code for that session look like if I use one HTML template only for the whole site and site is static HTML?
    How do I check if a session is already opened?
    Does PHP session “knows” who does it belong to, considering the fact that more than one user can be going through the site at any time?

It’s one variable only, called $variable.

Thanks

PHP_Chimp

6:05 pm on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have a read through the session [uk3.php.net] functions. There is most of the information that you asked for on that page.

However a brief answer to your questions -
1) The $_SESSION array works like any other. If you add elements to it then they remain in there, until get rid of them. So as long as there is a page reload and information sent through to the server even though everything is on one page you will be able to add, remove or manipulate the $_SESSION array at each page load.

2) You need to call session_start to open a session. You may well want to have a look at articles about session hijacking, as this is where people use already opened sessions. So in short you are better off starting a new session each time a person comes back. If you want information preserved from visit to visit then store it a a cookie on there computer, not in a persistent session.

3) When the session is started php gives a unique identifier to each session, the session id. This can either be stored as a cookie or passed along in the url. Using the url is not a good idea, as there are a lot more security problems with this. So this id is used to link the $_SESSION array to an individual (well hopefully an individual, but that is why you need to look up session hijacking).