【发布时间】:2015-10-02 05:11:25
【问题描述】:
我是 PHP 新手。 PHP 标头应该重定向到特定页面,但在我的情况下,PHP 重定向在 localhost 上工作正常,但是当我将相同的代码部署到服务器时,它在服务器中不起作用并抛出一个空白页面。我也尝试了以下建议:
- Redirect function is not working on the live server. But working on localhost
- PHP header location-redirect doesn't work - why?
这对我的情况没有帮助。
<?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';
}
}
?>
提前致谢。
【问题讨论】:
-
你遇到了什么错误?
-
空白页.. @Keerthi
-
<?php error_reporting(E_ALL);ini_set('display_errors',1);将此添加到您的页面顶部并检查确切的错误。 -
您是否到达了重定向(在浏览器中查看)。也许这只是这段代码中的另一个错误。
-
尝试回显
echo 'http://'.$host.$uri.'/'.$extra;exit;之类的网址,看看是否正确。如果是这样,请将其复制粘贴到地址栏中,看看你得到了什么