RE: [PHP] Returning values from functions

From: Date: Wed, 09 Jul 2003 22:55:02 +0000
Subject: RE: [PHP] Returning values from functions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-154650@lists.php.net to get a copy of this message
> function auth_user($logged_in) { > if (isset($logged_in)) { > list($s_username, $hash) = explode(',',$logged_in); > global $secret_word; > if (md5($s_username.$secret_word) == $hash) { > $username = $s_username; > return $username; > } else { > die ("You have tampered with your session."); > } > } else { > die ("Sorry, you are not logged in. Please log in and try again."); > } > } > auth_user($_SESSION['login']); > var_dump($username); $username = auth_user($_SESSION['login']); will actually assign the returned value to the variable $username. The $username variable in your function does not have global scope and only exist in the function.

« previous php.general (#154650) next »