Jump to content


Photo

session destroy


  • Please log in to reply
2 replies to this topic

#1 mcloan

mcloan
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 27 October 2006 - 02:42 PM

I am in the process of learning php and I am trying to get some concepts.  Below is some code for a logout script in the book I am reading.  I understand it all but one section.  I do not understand the line  if ($result_dest).  Can someone explain what is this check for?  The variable $result_dest was set to session_destroy(); so I would think it would have no value.  Also I am a little confused by an if statment without a condition.  For istance this is If ($result_dest), but normally I see ifs with a condition like if (!empty($result_dest)) or something like that.  Can some also explain what if statement without a condition is doing? 



<?php

// include function files for this application
require_once('bookmark_fns.php'); 
session_start();
$old_user = $_SESSION['valid_user'];  
// store  to test if they *were* logged in
unset($_SESSION['valid_user']);
$result_dest = session_destroy();

// start output html
do_html_header('Logging Out');

if (!empty($old_user))
{
  if ($result_dest)
  {
    // if they were logged in and are now logged out
    echo 'Logged out.<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
  echo 'You were not logged in, and so have not been logged out.<br />';
  do_html_url('login.php', 'Login');
}

do_html_footer();

?>




#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 27 October 2006 - 03:04 PM

Well basically the session_destroy() will end a session (although not unset any global session variables or session cookies) and if, when you call this method, it is successful in ending the session, it will return TRUE - or FALSE if it can't for some reason.

So that line that you are asking about, is actually saying "if the variable $result_dest is equal to TRUE, then...". PHP is intelligent enough to determine the condition on its own without you writing it all out. Conversely, if you inlude an exclamation mark before the variable, then it is as if you are saying "if the variable $result_dest is equal to FALSE, then...". You could of course do it the long way round and type

<?php 
if ($result_dest == TRUE) { 
}
?>

but then why would you?

#3 mcloan

mcloan
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 27 October 2006 - 11:36 PM

Thank you so much very helpful!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users