0

I'm trying to test my php script, so I need to (at least temporarily) get back some of the unset variables.

I mean:

page1.php:

<?php
session_start();
$_SESSION['var']="somevalue";
go_to("./page2.php");
?>

page2.php:

<?php
session_start();
use($_SESSION['var']);
unset($_SESSION['var']);
?>

Now when I go to page1->page2, then page1 again (then page2 again) page2 does not recognize $_SESSION['var'], so I need something like

if(!isset($_SESSION['var']))
{
set_back($_SESSION['var']); //But how ?
}

in page1.php.

Any help would be appreciated. Thanks!

void
  • 1,876
  • 8
  • 24
  • 30
  • 3
    Save the original value in `$_SESSION['temp_var']`? – Boaz Mar 24 '13 at 20:49
  • 1
    You've shredded your document and now asking for un-shredder? :-) – zerkms Mar 24 '13 at 20:49
  • @Boaz thanks, that's a good idea. I thought of another workaround like $_SESSION['var']['active']=1 or 0 since my 'var' was already an array. But I still want to know if there is a way to undo unset. zerkms no, fortunately I haven't lost anything yet :) – void Mar 24 '13 at 20:51

2 Answers2

0

I think that your problem is the local browser cache.

When you go back to page1 the response is served from your computer cache instead from the server so the session variable is not set again

Maks3w
  • 6,014
  • 6
  • 37
  • 42
0

There is no functionality in php that "rolls back" a session/variable that has been unset (Of course you could store the original value in temporarily session like Boaz suggested). What exactly are you trying to achieve?

bestprogrammerintheworld
  • 5,417
  • 7
  • 43
  • 72