0

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:

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.

SantMania
  • 81
  • 1
  • 11

1 Answers1

0

try to place the php code, at the beginning of the page, so that no output starts before,

    $host  = $_SERVER['HTTP_HOST'];
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'index.htm';
    $final_url = 'http://'.$host.$uri.'/'.$extra;
    header('Location:'.$final_url);

Replace code..

  • thanks for the reply, i can't put the code at the beginning because i have to redirect only when there is data in DB. – SantMania Jul 14 '15 at 16:37