I have a problem about redirecting the user. I want to land user on my specified page.
I tried
header("Location: http://www.website.com");
but it is not working.
When I log in as testing user with correct password and email, login.php page remains same. I want the user to land on index.php instead.
My second problem is that if the user is not logged in and tries to enter index.php, how do I redirect the user to login page (login.php)
here is my code for login (login.php) Note:(all php codes are above the html lines)
<?php
session_start();
$message = "";
if (count($_POST) > 0) {
$conn = mysql_connect("localhost", "user name", "password") or die(mysql_error());
mysql_select_db("db_name", $conn);
$result = mysql_query("SELECT * FROM users WHERE user_name='" . $_POST["user_name"] . "' and password = '" . $_POST["password"] . "'");
$row = mysql_fetch_array($result);
if (is_array($row)) {
$_SESSION["user_id"] = $row[user_id];
$_SESSION["user_name"] = $row[user_name];
} else {
$message = "Invalid Username or Password!";
}
}
if (isset($_SESSION["user_id"])) {
header("Location: login.php");
}
?>
where i want to redirect user and if not logged in want to land user on login.php