If I run the following PHP script the session variable auth_ok changes to
true resp. false only if I press the button 1 resp. 2 twice.
=============== ====
<?php
session_start() ;
if (!isset($_SESSI ON['auth_ok'])) {
$_SESSION['auth_ok'] = false;
}
echo "Username: " . $_POST['user'] . "<br>";
echo "Password: " . $_POST['pass'] . "<br>";
echo "Button 1: " . $_POST['button1'] . "<br>";
echo "Button 2: " . $_POST['button2'] . "<br>";
echo "Authentication : " . $_SESSION['auth_ok'] . "<br>";
if (isset($_POST['button1'])){
echo "Button 1 has been pressed<br>";
$_SESSION['auth_ok'] = true;
}
if (isset($_POST['button2'])){
echo "Button 2 has been pressed<br>";
$_SESSION['auth_ok'] = false;
}
?>
<html>
<body>
<form name="loginform " method="post" action="mytest. php">
Username: <input type="text" name="user" size="30" maxlength="30"> <br>
Passwort: <input type="password" name="pass" size="30"
maxlength="30"> <br>
<input type="submit" name="button1" value="Button 1">
<input type="submit" name="button2" value="Button 2">
</form>
</body>
</html>
=============== ====
The PHP error logs says
[24-Apr-2005 21:48:09] PHP Notice: Undefined index: button1 in
D:\WWW\php\_log in-sisi\mytest.php on line 10
or
[24-Apr-2005 21:48:28] PHP Notice: Undefined index: button2 in
D:\WWW\php\_log in-sisi\mytest.php on line 11
depending on the button I pressed.
What's wrong with my PHP script?
Stefan
true resp. false only if I press the button 1 resp. 2 twice.
=============== ====
<?php
session_start() ;
if (!isset($_SESSI ON['auth_ok'])) {
$_SESSION['auth_ok'] = false;
}
echo "Username: " . $_POST['user'] . "<br>";
echo "Password: " . $_POST['pass'] . "<br>";
echo "Button 1: " . $_POST['button1'] . "<br>";
echo "Button 2: " . $_POST['button2'] . "<br>";
echo "Authentication : " . $_SESSION['auth_ok'] . "<br>";
if (isset($_POST['button1'])){
echo "Button 1 has been pressed<br>";
$_SESSION['auth_ok'] = true;
}
if (isset($_POST['button2'])){
echo "Button 2 has been pressed<br>";
$_SESSION['auth_ok'] = false;
}
?>
<html>
<body>
<form name="loginform " method="post" action="mytest. php">
Username: <input type="text" name="user" size="30" maxlength="30"> <br>
Passwort: <input type="password" name="pass" size="30"
maxlength="30"> <br>
<input type="submit" name="button1" value="Button 1">
<input type="submit" name="button2" value="Button 2">
</form>
</body>
</html>
=============== ====
The PHP error logs says
[24-Apr-2005 21:48:09] PHP Notice: Undefined index: button1 in
D:\WWW\php\_log in-sisi\mytest.php on line 10
or
[24-Apr-2005 21:48:28] PHP Notice: Undefined index: button2 in
D:\WWW\php\_log in-sisi\mytest.php on line 11
depending on the button I pressed.
What's wrong with my PHP script?
Stefan
Comment