在我的网站,在每个PHP页面的顶部,我有一个HTTP重定向/头......当调用它
include_once“的header.php”;
此文件包含HTML。
在我的文件'authenticate.php'中,我想在登录回索引后重定向。
我的代码如下: header('Location:http://www.URLHERE.com/index.php');
但是在提交后,页面只是刷新。它不重定向。重定向在我的本地主机开发服务器上正常工作,但一旦我在线上传,它就停止工作。
这是因为我的头包含HTML,它在header()函数之前调用?请注意,'header.php'文件中的所有HTML都位于HEREDOC标记中。
这里是我的代码:
<?php // login.php
include_once 'header.php';
include_once 'functions.php';
require_once 'login_users.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to database:" . mysql_error());
mysql_select_db($db_database)
or die("Unable to find database:" . mysql_error());
if (isset($_POST['username']) &&
isset($_POST['pw_temp']))
{
$username = sanitizeString($_POST['username']);
$pw_temp = sanitizeString($_POST['pw_temp']);
$pw_temp = md5($pw_temp);
$query = "SELECT username,password FROM users WHERE username='$username' AND password='$pw_temp'";
if (mysql_num_rows(mysql_query($query)) == 0)
{
die("Wrong info");
}
else
{
$_SESSION['username'] = $username;
$_SESSION['password'] = $pw_temp;
$_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];
header('Location: http://www.URLHERE.com/index.php');
}
}
...more code down here
可能重复http://stackoverflow.com/questions/8028957/headers-already-sent-by-php) – deceze