I have to make a workaround for some code that basically means I need to somehow track what page has just clicked on a link to my current code. Then deal with that accordingly.
HTTP_REFERER would be perfect if the target machine wasn't running IE (which doesn't like to display this information!)
All I need is the previous pages name, or some unique way of identifying it without passing variables through.
I had toyed with the idea of using sessions, but I don't know the best way to randomly allocate and update them as a user could click on several candidate pages before clicking on the link to the code with the tracker.
It is being deployed in an enclosed environment where we can control that stuff, but that is academic since IE doesn't want to play ball!
How do I go about setting up sessions to work differently from most?
The way I see it I want one session variable, which gets updated dependent on the page you are on and can be easily tracked so I know how to act when the session variable appears.
Ha, turns out I was being an idiot, I know how to handle sessions fine - I was over complicating what they needed to do in my head!
[edit]
Actually no, could someone give me some pointers? I have set up my session variable but it doesn't wanna pass itself onto my page that is waiting for it.
Last edited by tosbourn; 08-28-2008 at 04:07 PM..
Reason: It would appear I am being a double idiot.
The first time around the string gets printed out, the second time around (and any other times even going back to the first page) it will say tester.php (I want to to say home.php)
I don't have that problem at all; it acts just as expected. Unless I move the ="tester.php" code outside of the else loop, it never gets executed, and if it does, resetting the value to "home.php", well, resets it.
I'd take a look at your cookie settings. Make sure that above is really *all* you've got in your test pages, and try different browsers.
Page two is 100% just that, page 1 has a load more stuff on it.
Basically this is a project I have been assigned that someone else had completed but not properly - I have to fix it up (including making it IE proof).
Here is sessions.php - one of the things called on that first page before I declare my session. This is the only thing that I would think would come close to affecting sessions.
function sess_connectDB(){ /* function to connect to the backend database with local db defined parameters. */ try { $dbh = new DBFactory(); return $dbh; } catch(ADODB_Exception $e){ header("Location: nodb.php"); exit; } } function sopen($save_path, $session_name){ /* No need to do anything here. */ return true; } function sclose(){ /* No need to do anything here. */ return true; } function sread($id){ /* Reads session data from the database */ $dbh = sess_connectDB(); $sql = "SELECT * FROM `TS::Sessions` WHERE sid='$id'"; $dbh->SetFetchMode("ASSOC"); $rs = $dbh->Execute($sql); $row = $rs[0];//->fields; //print_r($row); return $row['sdata']; } function swrite($id, $sess_data) { /* Writes session data to the database */ try { $dbh = sess_connectDB(); $clean_data = $dbh->qstr($sess_data); $timestamp = date(STAMP_FORM); $sql = "DELETE FROM `TS::Sessions` WHERE sid='$id'"; $dbh->Execute($sql); $sql = "INSERT INTO `TS::Sessions` (sid, sdata, modtime) VALUES('$id', $clean_data, '$timestamp')"; $dbh->Execute($sql); //printr($sql); } catch (Exception $e){ var_dump($e); } } function sdestroy($id){ /* We are finished with the db, so wipe the session */ $dbh = sess_connectDB(); $dbh->Execute("DELETE FROM `TS::Sessions` WHERE sid='$id'"); $_SESSION= array(); } function s_gc($maxlifetime){ /* Garbaage collection. */ $dbh = sess_connectDB(); $ts = time() - $maxlifetime; $timestamp = date(STAMP_FORM, $ts); $dbh->Execute("DELETE FROM `TS::Sessions` WHERE modtime < '$timestamp'"); }
// Make PHP use *our* session handling. if (session_set_save_handler( "sopen", "sclose", "sread", "swrite", "sdestroy", "s_gc" )===false){ die("Sessions are broken"); }
// As this will be included in any page that wants session access, we might as well start it here. session_start();
But I can't see anything in it that would stop you making your own sessions (he has used them in the code and I am assuming they are doing their job!!)
The original coder has replaced default session storage with their own database solution, this means that any session data created in the first page will not be stored in the normal PHP session location and hence will not be available to your second page _unless_ it also includes this code and hence shares the replacement session storage.
The solution is either to comment out the replacement session handling throughout (but there may be a very good reason why it does this) or to include the same session.php in your second (test) page and anywhere else that you want to handle session data.