I can't redirect to index.php page after login.
This happens on the website that I have deployed, but it doesn't happen on localhost (Can redirect to index.php).
I deploy website to Microsoft Azure and deploy database to freemysqlhosting.net(free).
I have tried the solutions here and here, but still can't redirect.
And here's the code login.php:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Variant'C - Your Covid Solutions</title>
<link rel="icon" href="../images/logo.ico" type="image/x-icon">
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<?php
require('db.php');
session_start();
// When form submitted, check and create user session.
if (isset($_POST['username'])) {
$username = stripslashes($_REQUEST['username']); // removes backslashes
$username = mysqli_real_escape_string($con, $username);
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con, $password);
// Check user is exist in the database
$query = "SELECT * FROM `users` WHERE username='$username'
AND password='" . md5($password) . "'";
$result = mysqli_query($con, $query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if ($rows == 1) {
$_SESSION['username'] = $username;
// Redirect to user dashboard page
header("Location: index.php");
} else {
echo "<div class='form'>
<h3>Incorrect Username/password.</h3><br/>
<p class='link'>Click here to <a href='login.php'>Login</a> again.</p>
</div>";
}
} else {
?>
<form class="form" method="post" name="login">
<h1 class="login-title">Login</h1>
<input type="text" class="login-input" name="username" placeholder="Username" autofocus="true"/>
<input type="password" class="login-input" name="password" placeholder="Password"/>
<input type="submit" value="Login" name="submit" class="login-button"/>
<p class="link"><a href="registration.php">New Registration</a></p>
</form>
<?php
}
?>
</body>
</html>
What's wrong? Is it the code or is it from the deployment?
Thank you in advance :)