Hi there.
I got this weird problem.
The code below works on my own machine running IIS 5.0, PHP 4.2.2 and MySql 3.23.47-nt.
When I enter the correct username and password I get the javascript-alert and is sent back to the loginform.
BUT if i start without entering anything and
clicking the submitbutton, and then on the second try enters the right words, I am logged in correctly.
The webhotel also runs PHP 4.2.2 and there are no problems with the MySql-database.
Any suggestions???
Sincerely
Kurt
PAGE 1: entrance.php
<FORM ACTION="login.php" METHOD="post">
Username:<INPUT TYPE="text" NAME="user" SIZE="10"><BR>
Password:<INPUT TYPE="password" NAME="pass" SIZE="10"><BR>
INPUT TYPE="submit" VALUE="Login">
</FORM>
Page 2: login.php
<?
$user=$POST['user'];
$pass=$POST['pass'];
session_start();
session_register("clubpass");
session_register("user");
$md5pass = md5($pass);
$conn = mysql_connect ("localhost", "kurt", "xyz");
mysql_select_db("club");
$result = mysql_query("SELECT bruger, brugerpassword FROM brugere WHERE bruger='$user' AND brugerpassword='$md5pass'");
$num=mysql_numrows($result);
if($num=="1"){
$vakkpass = "ok";
header("Location: enter.php");
exit;
}
if ($num=="0"){
echo "<SCRIPT>alert(\"Uregistreret brugernavn ($user) og/eller password ($pass). Prøv igen!\");history.go(-1)</SCRIPT>";
}
?>
Page 3+: the sessioncode looks like this:
<?
session_start();
if ($_SESSION['clubpass'] != "ok") {
Header("Location: ../entrance.php");
exit;
}
?>