Forum Moderators: coopster
Can somebody point to the error here please?
<?php
// we must never forget to start the session
session_start();
$errorMessage = '';
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
include 'connect.php';
$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
// check if the user id and password combination exist in database
$sql = "SELECT user_id
FROM tbl_auth_user
WHERE user_id = '$userId'
AND user_password = PASSWORD('$password')";
$result = mysql_query($sql)
or die('Query failed. ' . mysql_error());
if (mysql_num_rows($result) == 1) {
$_SESSION['db_is_logged_in'] = true;
// after login we move to the main page
header('Location: main.php');
exit;
} else {
$errorMessage = 'Sorry, wrong user id or password';
}
include 'library/closedb.php';
}
?>
Note: HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:
Just a heads up.
In regards to the new issue, are you starting the session in main.php? You must do that first.
I changed the above location. But no success.
It still stays on the same page - login.php
header("Location: http://example.com/logged_in/");
We also have a great thread in the PHP Forum Library on User Authentication [webmasterworld.com]. It's always a good reference :)
But when I try to run this on hosting site, it doesn't take it. I have tried several different ways to redirect. But nothing works.
Does it have to do with the settings of php.ini file?