I'm new to PHP. PHP header should redirect to specific page, but in my case PHP redirect is working on localhost fine but when I deploy the same code into server it is not working in the server and throwing a blank page. I also tried the below suggestions:
- Redirect function is not working on the live server. But working on localhost
- PHP header location-redirect doesn't work - why?
Which did't help in my case.
<?php
include('../config/db.html');
if(!isset($_SESSION)){
session_start();
}
$msgsuccess = '';
if(!empty($_GET['msgsuccess'])){
$msgsuccess = $_GET['msgsuccess'];
}
if(isset($_POST) && !empty($_POST)){
if(!empty($_GET['url'])){
$url = $_GET['url'];
}
if(!empty($_POST['password'])){
$pass = md5($_POST['password']);
}
if(!empty($_POST['username'])){
$email = trim($_POST['username']);
}
$query = "select * from users where email = '$email' and password = '$pass'";
$exec_query = mysql_query($query);
$row = mysql_fetch_array($exec_query);
if(!empty($row)){
$_SESSION['adminfirstname'] = $row['firstname'];
$_SESSION['adminID'] = $row['id'];
$_SESSION['logged_in_admin'] = true;
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'index.htm';
header("Location: http://$host$uri/$extra");
die();
}
else{
$msgsuccess = 'INVALID CREDENTIALS!! PLEASE ENTER VALID EMAIL OR PASSWORD';
}
}
?>
Thanks in advance.