View Full Version : Session variables being overwritten:

02-26-2007, 05:16 AM

When a user lands on my home page, I grab several variables (referring page etc) and pass them into session variables. I then pass these into the database when they register on my site. The problem is that if the user clicks around on my site and clicks the link back to the home page, the same code that initially created the session variables overwrites them.

Here's the code for the variable $_SESSION['src'] that I want to grab from a GET parameter:

$_SESSION['src'] = $source;

Again, the variables are writing just fine. The problem is that they are lost when the user clicks back onto the home page for a second time via the "Home" link. Then they overwrite to null because there is no GET parameter in the URL. Then when the user registers, the variable isn't passed into the database, it just comes up blank.

Can anyone suggest a fix for this?


02-26-2007, 02:45 PM
Yes, it is referred to as a "one-shot". You only set the variable if it does not exist. Once it exists, you don't set it again -

$_SESSION['src'] = $source;