-2

I am trying to destroy all form sessions as follows: i have a sidenav.php bar, when the user clicks on it, it goes to this page:

<?php
session_start();
unset($_SESSION['applicationID']);
session_destroy();
echo'<html><script>window.location="index.php?url=newapplication&id="'.$userid.';</script></html>';
?>

which in turn bring up the new application form, however, the "$userid" fails to echo. it comes back as blank. any ideas?

NULL
  • 1,559
  • 5
  • 34
  • 60

2 Answers2

1

**$userid ** NEEDS (you have no option) to be defined BEFORE you can use it.

Whatever you have defined in your main script will stay there because that script has finished his execution time.

You can pass that value via either GET, POST, SESSION or COOKIE. Otherwise you will have to dig on your database for that username but then again, you need to "keep" a session or a number to "go back to" in order to search for it.

What you are actually trying to do could work as follows if you HAVE the userid variable defined in SESSION:

<?php
session_start();
unset($_SESSION['applicationID']);
echo'<html><script>window.location="index.php?url=newapplication&id='.$_SESSION['userid'].'"';
session_destroy();
echo '</script></html>';

?>

Solrac
  • 924
  • 8
  • 23
0

You have closed window.location before $userid.The output of your above code will be

<html><script>window.location="index.php?url=newapplication&id="the_value_of_$userid;</script></html> 

Use the code below

<?php
session_start();
unset($_SESSION['applicationID']);
session_destroy();
echo'<html><script>window.location="index.php?url=newapplication&id='.$userid.'";</script></html>';
?>

Hope this helps you

Utkarsh Dixit
  • 4,267
  • 3
  • 15
  • 38