dongpinken0498 2015-07-13 19:28
浏览 40

PHP标题('位置:..')不在服务器上工作[重复]

This question already has an answer here:

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. 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.

</div>
  • 写回答

1条回答 默认 最新

  • duanbinren8906 2015-07-13 19:35
    关注

    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..

    评论

报告相同问题?

悬赏问题

  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
  • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档