Jump to content

Logging Out Help!


Trium918

Recommended Posts

Will the script below destroy the $_SESSION['id']; even if it

isn't being tested against isset() and empty() ?

 

<?php
if (!empty($_SESSION['valid_user']) && !empty($_SESSION['password']))
{
  if (isset($_SESSION['valid_user']) && isset($_SESSION['password']))
  {
    unset($_SESSION['user']); 
    unset($_SESSION['pwd']);
    unset($_SESSION['id']);   // DESTROY
    $_SESSION = array(); // reset session array
    session_destroy();   // destroy session.
    echo "<p class='genmed'>Logged out.</p><br>";
    do_html_url("login.php", "Login");
  }
  else
  {
   // they were logged in and could not be logged out
    echo "Could not log you out.<br>";
  }
}
else
{
  // if they weren't logged in but came to this page somehow 
  if(!$logged_in){
    echo "<p class='genmed'>You were not logged in, and so have not been logged out.</p><br>";
    do_html_url("login.php", "Login");;
  }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/53665-logging-out-help/
Share on other sites

Register the session ID, then after you perform the above script, try echoing it out somewhere to see if it still exists.

 

or...

 

<?php

if (isset($_SESSION['id'])){
   echo "It is still there...";
} else {
   echo "It was destroyed.";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/53665-logging-out-help/#findComment-265284
Share on other sites

Register the session ID, then after you perform the above script, try echoing it out somewhere to see if it still exists.

 

or...

 

<?php

if (isset($_SESSION['id'])){
   echo "It is still there...";
} else {
   echo "It was destroyed.";
}

?>

 

I tested it twice. I tested it onced on the logout page, and

it echo "It was destroyed". The second time I tested it I added

the code you gave me to the members page where the session is

set and it echo "It was destroyed" also.

 

What can I try next?

Link to comment
https://forums.phpfreaks.com/topic/53665-logging-out-help/#findComment-265292
Share on other sites

When the sessions are granted parameters, are you using session_start(), or just creating them out of the blue?

 

And plus the following isn't really necessary:

 

    unset($_SESSION['user']); 
    unset($_SESSION['pwd']);
    unset($_SESSION['id']);   // DESTROY
    $_SESSION = array(); // reset session array
    session_destroy();   // destroy session.

 

Just have something like:

 

<?php
session_start();
if (!empty($_SESSION['valid_user']) && !empty($_SESSION['password'])) //this and the next line two down from there are exactly the same, if the value ISNT empty, meaning it's set, so isset is useless
{
  if (isset($_SESSION['valid_user']) && isset($_SESSION['password']))
  {
    session_destroy();   // destroy session.
    echo "<p class='genmed'>Logged out.</p><br>";
    do_html_url("login.php", "Login");
  }
  else
  {
   // they were logged in and could not be logged out
    echo "Could not log you out.<br>";
  }
}
else
{
  // if they weren't logged in but came to this page somehow 
  if(!$logged_in){ //where is this variable defined?
    echo "<p class='genmed'>You were not logged in, and so have not been logged out.</p><br>";
    do_html_url("login.php", "Login"); //only needed one end quote there
  }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/53665-logging-out-help/#findComment-265294
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.