Skip to content

Instantly share code, notes, and snippets.

@smunchi
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save smunchi/888af1499974a21694da to your computer and use it in GitHub Desktop.

Select an option

Save smunchi/888af1499974a21694da to your computer and use it in GitHub Desktop.
Use of HTTP_REFERER to delete session data
Use of $_SERVER['HTTP_REFERER'];
I assume in a.php
<?php
session_start();
$_SESSION['hello'] = "Your content here";
?>
In b.php you want to show your session data and you are also checking what is the previous page
<?php
session_start();
$previousUrl = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_PATH);
if($previousUrl == '/phpTest/php/c.php') {
unset($_SESSION['hello']);
}
echo $_SESSION['hello'];
?>
And in c.php you might have a back button or there is also browser back button
<p>Show your confirmation</p>
<a href="b.php">Back or back from browser button<a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment