Php头命令在一个文件中工作,但在另一个文件中不工作
惠, 我当前的目录结构如下 Admin index.php,country.php Classesconnection.php、login.php、country.php 页眉 页脚 index.php includeHeader.php,footer.php 我的问题是,在Web服务器上,当我在/admin/country.php中并使用form post方法和操作集将一个国家添加到/classes/country.php时,我的头语句HeaderLocation:../admin/country.php工作正常,但当我在根目录的索引页上并尝试使用form action classes/login.php登录时,成功登录时,我使用headerLocation:../Admin/index.php它从不重定向,但一切正常我的本地服务器,我不知道这里有什么问题,非常感谢您的帮助, 我搜索了这个论坛和其他论坛,并尝试使用他们告诉我的技术,但没有任何效果 我的索引页 我的行政部 下面是我的login.php脚本Php头命令在一个文件中工作,但在另一个文件中不工作,php,redirect,header,Php,Redirect,Header,惠, 我当前的目录结构如下 Admin index.php,country.php Classesconnection.php、login.php、country.php 页眉 页脚 index.php includeHeader.php,footer.php 我的问题是,在Web服务器上,当我在/admin/country.php中并使用form post方法和操作集将一个国家添加到/classes/country.php时,我的头语句HeaderLocation:../admin/count
<?php
ob_start();
include_once("classes/connection.php");
?>
<?php
class login
{
public static function validateLogin($userName,$password)
{
if(isset($userName) && isset($password))
{
$connection = dbconnection::getConnection();
$query = "Select * from tbllogin Where loginID ='" . $userName .
"' and password = '" . $password . "'";
$result = mysql_query($query);
$rowsAffected = mysql_affected_rows();
if($rowsAffected==0)
{
//header("Location: ../index.php/");
//exit();
return false;
}
else
{
while($row = mysql_fetch_array($result))
{
//working
$role = $row["role"];
if($role == "Admin")
{
//header('Location: ../Admin/index.php');
//exit();
return true;
}
else
{
//echo "hello";
//header("Location: ../index.php/");
//exit();
return false;
}
//return $result;
//header("Location: ../index.php");
}
}
}
else
{
//header("Location: ../index.php/");
return false;
}
}
}
?>
<?php
if(isset($_POST["btnSumbit"]))
{
$isValid = login::validateLogin($_POST["userID"],$_POST["password"]);
if(isset($isValid))
{
if($isValid ==true)
{
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'Admin/index.php';
header("Location: http://$host$uri/$extra");
exit();
}
}
}
ob_end_flush();
?>不要对相对路径使用头重定向。您应该重定向到前端URL路径或绝对路径
您的classes/login.php可能是index.php中的一个包含文件,因此您实际上是在尝试跳出web服务器目录,这就是为什么它在本地工作,而不是在服务器上工作。请显示一些实际代码。它将帮助社区帮助您。当它不重定向时,您会遇到什么错误?您是否打开了错误和警告以便查看问题所在?@anigel->我没有收到任何错误,只是当我以action classes/login.php的形式从index.php登录时,它不会重定向,然后在classes/login.php中调用headerLocation:../Admin/index.php,它不会工作,但是,当我在/Admin/country.php中调用表单操作../classes/country.php,然后使用headerLocation:../Admin/country.php时,它会按预期重定向!!对于源代码,请从这里下载:*您能告诉我如何重定向到前端url路径或绝对路径吗**