mcloan Posted October 27, 2006 Share Posted October 27, 2006 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? [code]<?php// include function files for this applicationrequire_once('bookmark_fns.php'); session_start();$old_user = $_SESSION['valid_user']; // store to test if they *were* logged inunset($_SESSION['valid_user']);$result_dest = session_destroy();// start output htmldo_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();?>[/code] Quote Link to comment Share on other sites More sharing options...
gmwebs Posted October 27, 2006 Share Posted October 27, 2006 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 [code]<?php if ($result_dest == TRUE) { }?>[/code] but then why would you? Quote Link to comment Share on other sites More sharing options...
mcloan Posted October 27, 2006 Author Share Posted October 27, 2006 Thank you so much very helpful! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.