I’m desperate for help! I’ve been searching for an answer for hours now and I cannot find anything that works!
I’m trying to create a login-script that will allow users that are already in a database to connect. I have the files login.php, login_success.php and logout.php.
The problem is that the script won’t redirect the browser after a successful login to the page login_success.php. Yes, I have checked over and over again and there is no white-space before the <?php tag anywhere. I did get that error message earlier when I had one after the ?>-tag in connect_database.php with my settings for database connection.
This is the code for login.php
[code=php]<?php
session_start();
ini_set(‘display_errors’, 1);
error_reporting(E_ALL);
if(isset($_POST[“userID”]) && isset($_POST[“password”])){
include “conn/config.php”;
include “conn/connect_database.php”;
$userID = mysql_real_escape_string($_POST[“userID”]);
$password = mysql_real_escape_string(sha1($_POST[“password”]));
$sql = “SELECT username FROM users WHERE username = ‘$userID’ AND password = ‘$password'”;
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) == 1){
$_SESSION[“login”] = true;
header(“Location: edit/login_success.php”); //here have I tried both relative and absolute URLs
exit;
}
else {$error_message = “<p>Du har angivit fel användarnamn eller lösenord!</p>”;}
mysql_close($opendb);
}
?>
…
<form action=”” method=”post” name=”loginform” id=”krs-login_form”>
<input name=”userID” type=”text” />
<br />
<input name=”password” type=”password” size=”21″/>
<input type=”submit” onclick=”” value=”Ok” />
</form>
<?php echo “<strong><font color=’#ff0000′>”.$error_message.”</font></strong>”;?>
Btw, I wonder if there’s a better way to handle the last part with the $error_message? Because now I always get a small error because the $error_message variable hasn’t been assigned a value ’til after I’ve tried to login.
Login_success.php
[code=php]<?php
session_start();
if(isset($_SESSION[“login”]) || $_SESSION[“login”] !== true){
header(“Location: ../index.php”);
exit;
}
?>
…
logout.php
[code=php]<?php
session_start();
if (isset($_SESSION[“login”])) {
unset($_SESSION[“login”]);
}
header(“Location: ../index.php”);
?>
Please reply with any idea you might have. I have to often not received any answers at all to questions I have asked here in this forum. Thanks ?