We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

PHP sessions clearing on Safecracker submit/JS back link

Development and Programming

Frank Harrison's avatar
Frank Harrison
154 posts
13 years ago
Frank Harrison's avatar Frank Harrison

Hi All

I’m trying to use PHP sessions to keep track of where a user has recently been. I need to record whether they were most recently on the home page or a Solspace Supersearch results page, and, if the later, record what URL they were at.

So I’ve got the following embedded at the top of every page:

<?php
// update last_search session variable if needed
session_start();

// get our segment variables
$s1 = $this->EE->uri->segment(1);
$s2 = $this->EE->uri->segment(2);
$s3 = $this->EE->uri->segment(3);

if ($s1 == "" ) {
 // if we're on home page, we record that
 $_SESSION['last_search']="home";
} else if ($s1 == "search")) {
 // if we're on a search page, we record our url
 $_SESSION['last_search'] = "search";
 if ($s2) $_SESSION['last_search'] .= "/" . $s2;
 if ($s3) $_SESSION['last_search'] .= "/" . $s3;
} else if (!isset($_SESSION['last_search'])) {
 // or if it's not been set yet, add a blank value for it
 $_SESSION['last_search']="";
}
?>

I then use the last_search session variable later in the templates to do different things, depending on where the user has been. It all works fine except for one thing: when I do certain actions (specifically clicking a Javascript history “back” link or submitting a Safecracker form), the variable is reset to “home”.

Both the JS link and Safecracker form are in domainname.com/view/, and the Safecracker form also submits to that template, so they shouldn’t be effected by the code above.

I’m not sure why it would do it for the JS history back link, but I’m guessing that for the Safecracker submit, it’s being directed first to the home URL (ie domainname.com/index.php), which resets my session variable, and then to the one specified in the Safecracker tag.

Any ideas if that’s the right diagnosis? And any ideas how to get round this?

Thanks loads, and sorry for such a complicated question!

Frank

Ps. I’ve also tried using the Sessions Variable Plugin but that had the same problem.

       
Frank Harrison's avatar
Frank Harrison
154 posts
13 years ago
Frank Harrison's avatar Frank Harrison

I know you’re not meant to bump, but is anyone able to shed any light on this?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.