hye,我当前的目录结构类似
- Admin(index.php,country.php)
- 类(connection.php、login.php、country.php)
- header.php
- 页脚.php
- index.php
- includes(header.php,footer.php)
我的问题是,在Web服务器上,当我在/admin/country.php中并使用表单发布方法和操作集添加国家/地区时,我的标题语句"标题("位置:../admin/countryphp")"工作正常,但当我在根目录中的索引页上并尝试使用表单操作登录时"classes/login.php"成功登录后,我使用标头("Location:../Admin/index.php")它从不重定向,但我的本地服务器一切正常,我不知道这里有什么问题,如果有任何帮助,我将不胜感激,我已经搜索了这个论坛和其他人,并试图使用他们所说的技术,但什么都不起作用
我的索引页index.php
我的管理部分Admin/Country.php
我的login.php脚本在下面
<?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服务器目录,这就是为什么它在本地工作,但在服务器上不工作。