I have created function to authenticate a user. It sets a variable to true and then every page will make sure that variable is set to true. The only problem is that the function gopher_auth() is not returning a value??
$auth, $userid, and $password are all set via session_register in the form that submits to the page which calls the function.
I will first show how the function is called and then the function.
THE CALLING OF THE FUNCTION.
//Include global functions
include("function_code.php");
//Check to see if user is authenticated.
gopher_auth();
if ( $auth == true ) {
// You are authenticated!!
session_unregister("password");
exit;
} else {
header( 'HTTP/1.0 401 Unauthorized' );
echo '<br>Authorization Required.<br>';
exit;
}
THE FUNCTION ITSELF.
function gopher_auth() {
if (isset( $userid ) && isset($password)) {
//Call function to connect to database.
gopher_connect();
// Formulate the query
$sql = "SELECT * FROM users WHERE userid = '$userid' AND password = '$password'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
return $auth;
} else {
$auth = false;
return $auth;
}
print "auth = $auth";
}
}