Problemet har udviklet sig lidt til først at omhandle et log ind probblem. I koden herunder kan man logge sig ind, problemet er bare at den sender brugeren til næste side efter log ind, dog uden at brugeren har skrevet hverken brugernavn eller password.
<?
ob_start();
?>
<?php
session_start();
require("sidehoved.html");
if (isset($HTTP_POST_VARS['userid']) && isset($HTTP_POST_VARS['pass']))
{
// if the user has just tried to log in
$userid = $HTTP_POST_VARS['userid'];
$pass = $HTTP_POST_VARS['pass'];
$db_conn = mysql_connect("localhost", "root") or die(mysql_error());
mysql_select_db('registrering', $db_conn) or die(mysql_error());
$query = "select * from kunde where brugernavn='$userid' and pass='$pass'";
$result = mysql_query($query, $db_conn) or die(mysql_error());
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$HTTP_SESSION_VARS['valid_user'] = $userid;
}
}
?>
<html>
<body>
<!--<h1>Home page</h1> -->
<?
if (isset($HTTP_SESSION_VARS['valid_user']))
{
header("Location:
http://127.0.0.1/registrering/sevenparts10.php");
exit;
// echo 'You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].' <br />';
// echo '<a href="logout.php">Log out</a><br />';
}
else
{
if (isset($userid))
{
// if they've tried and failed to log in
echo 'Du har skrevet forkert brugernavn og password !';
}
else
{
// they have not tried to log in yet or have logged out
echo 'You are not logged in.<br />';
}
}
// provide form to log in
?>
// <?
// ereg('^http://([a-zA-Z0-9\-\.]+)', $_SERVER["HTTP_REFERER"],$temp_referrer);
// if ($temp_referrer[1]=="
http://127.0.0.1/registrering/indannonce.php") {
// echo "Du skal logge ind før du kan indrykke en annonce!";
// }
// ?>
<center>
<form method="post" action="loginform.php">
<table>
<tr><td>Userid:</td>
<td><input type="text" name="userid"></td></tr>
<tr><td>Password:</td>
<td><input type="PASSWORD" name="pass"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" value="Log in"></td></tr>
</table></form>
<br>
<br>
<br>
<br>
<br>
<?
require("sidefod.html");
ob_end_flush();
?>