|
Posted by Vincent Delporte on 02/08/07 00:15
Hello
I'm learning how to use sessions to check at the top of every page
that the user has been authenticated, but I'm having a problem with
isset():
------------------------------------
<?php
if(!$PHPSESSID) {
//First time: Let's check login/passwd
//BAD $login = isset($_POST["login"])? $_POST["login"] : '';
$login = isset($_POST["login"])? $_POST["login"] : NULL;
$password = isset($_POST["password"])? $_POST["password"] :
NULL;
if(!isset($login) or !isset($password)) {
?>
<form action="<?php echo $PHP_SELF; ?>" method=POST>
Login: <input type="text" name="login"
size="20" value=""><br>
Pass: <input type="password" name="password"
size="10" value=""><br>
<input type="submit" value="OK">
</form>
<?php
} else {
//Shown after clicking on OK, even with
//one of the fields empty!
print "login = $login, password = $password";
}
} else {
print "session = ". $PHPSESSID . "<p>";
}
?>
------------------------------------
If the user doesn't fill in either the Login or Password field in the
form, I expected the empty field to return FALSE when passing it to
isset()... but this doesn't work. Obviously, I'm doing something wrong
:-/
Thanks for any tip :-)
Navigation:
[Reply to this message]
|