Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.