/    Sign up×
Community /Pin to ProfileBookmark

PHP-login-script error! Help!

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″/>
&nbsp;&nbsp;
<input type=”submit” onclick=”” value=”Ok” />
</form>

<?php echo “<strong><font color=’#ff0000′>”.$error_message.”</font></strong>”;?>
[/code]

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;
}
?>

[/code]

logout.php

[code=php]<?php
session_start();

if (isset($_SESSION[“login”])) {
unset($_SESSION[“login”]);
}

header(“Location: ../index.php”);
?> [/code]

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 ?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @gunnarflax spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...