当我在服务器上传时,我的PHP代码无效。当我在localhost上运行它时工作正常......为什么?
<?php
ob_start();
include 'CUserDB.php';
session_start();
include 'config.php';
$myusername=$_POST['txtusername'];
$mypassword=$_POST['txtpassword'];
$typ= $_POST['type'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$typ = stripslashes($typ);
$myusername = mysql_real_escape_string($myusername);
$mypassword=mysql_real_escape_string($mypassword);
$typ = mysql_real_escape_string($typ);
try {
$oUser = new CUserDB();
$result = $oUser->Login($myusername,$mypassword,$typ);
}
catch (PDOException $pe)
{
die("Error occurred:" . $pe->getMessage());
}
if($result[0][0][UserName] != '')
{
session_start();
$_SESSION['UserId'] = $myusername;
if( $typ == "Dealer")
{
header('location:Dealer/ManageProfile.php');
}
else if ($typ == "Individual")
{
header('location:Individual/managep.php');
}
else
{
header('location:Builder/managep.php');
}
}
else
{
header('location:header.php');
}
?>
当我在服务器上运行时,这是checklogin页面。点击登录后,此页面正在被调用。但是在服务器上,它在登录页面后重新定位,它停留在checklogin.php页面上。为什么会在服务器上发生这种情况?
答案 0 :(得分:2)
根据http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html,Location标头应该是绝对URI,例如:
Location: http://yourserver/header.php
此外,正确的标题名称为Location
,大写
冒号字符和标题值之间也应该出现空格字符。
根据PHP文档:
你通常可以使用$ _SERVER ['HTTP_HOST'],$ _SERVER ['PHP_SELF']和dirname()自己创建一个相对的URI:
<?php
/* Redirect to a different page in the current directory that was requested */
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
现在,我无法确定您的重定向在编写时不起作用,可能还有其他问题,但您应该尽可能地尊重HTTP协议以避免兼容性问题。
答案 1 :(得分:1)
phpinfo()
并查看已启用的内容。