【发布时间】:2023-04-05 14:08:01
【问题描述】:
嘿, 我当前的目录结构是这样的
- 管理员(index.php、country.php)
- 类(connection.php,login.php,country.php)
- header.php
- footer.php
- index.php
- 包括(header.php,footer.php)
我的问题是,当我在 /admin/country.php 并使用表单发布方法和操作设置为 /classes 添加国家/地区时,在 webserver 上/country.php 我的标题语句“Header("Location: ../Admin/country.php")" 工作正常,但是当我在根目录的索引页上时尝试使用表单操作 "classes/login.php" 登录,成功登录后我使用 header("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();
?>
【问题讨论】:
-
请显示一些您的实际代码。它将帮助社区能够帮助您。
-
不重定向时会出现什么错误?您是否打开了错误和警告,以便查看问题所在?
-
@anigel -> 我没有收到任何错误,当我使用表单操作 classes/login.php 从 index.php 登录然后在 classes/login.php 中我调用 header( “位置:../Admin/index.php”)并且它不起作用,但是当我在“/Admin/country.php”并调用表单操作../classes/country.php然后使用标题时(“位置:../Admin/country.php”)它按预期重定向!!e