...

View Full Version : Session variables being overwritten:



Morf
02-26-2007, 05:16 AM
Hello.

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:



<?php
session_start();
$source=$_GET['src'];
require("somefile.php");
require("someotherfile.php");
$_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?

Appreciated.

CFMaBiSmAd
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 -

if(!isset($_SESSION['src'])){
$_SESSION['src'] = $source;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum