在检查数据库页面后,我的登录脚本被重定向但页面搞砸了。我的登录页面和仪表板页面在登录页面打开,而不是重定向到仪表板。
我的登录检查脚本在
下面<?php
include_once'\..\database\connection.php';
class loginDetails extends connection{
private $result,$query,$count;
public function checkLogin($adusername,$adpassword){
$adusername=mysqli_real_escape_string($this->con,$adusername);
$adpassword=mysqli_real_escape_string($this->con,$adpassword);
$this->query= "select * from quoteslogin where Username='$adusername' AND Password='$adpassword'";
$this->result= mysqli_query($this->con,$this->query);
$this->count= mysqli_num_rows($this->result);
if($this->count < 1)
{
echo "Access Denied";
}
else
{
$row= mysqli_fetch_array($this->result);
$_SESSION["quotes_username"]=$row["Username"];
$_SESSION["quotes_password"]=$row["Password"];
header("Location: http://www.google.com/");
// header("Location:admin/dashboard.php");
exit();
}
}
我把google.com放在该位置,但我的登录页面只显示加载图片和谷歌上的dosnt重定向没有任何错误。我的脚本正在运行,因为我检查了它并且它正确回显。 我的连接字符串
class connection {
private $host="localhost",$dbusername="root",$dbpassword="",$dbname="quotation";
public $con;
public function __construct() {
$this->con= mysqli_connect($this->host, $this->dbusername, $this->dbpassword, $this->dbname);
}
}
如果我在标题之前使用flush()而不是脚本显示“标题已发送....”如果我删除它就像图像
答案 0 :(得分:1)
我认为它已经发送了一个警告标题,因为一旦已经发送了标题块,就无法使用header()函数添加任何标题行。所以尝试使用
echo '<script language="javascript"> window.location="admin/dashboard.php";</script>'
答案 1 :(得分:0)
我将此用于重定向,它使用后备redirect::avert($url);
class Redirect
{
public static function avert($url)
{
if (!headers_sent())
{
//header has not been sent so redirect
header($url, true, 302);
exit;
}
else
{
//redirect using javascript
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
//javascript turned off so redirect with meta-refresh
echo '<noscript>';
echo '<META HTTP-EQUIV="Refresh" Content="0; URL="' . $url . '">';
echo '</noscript>';
exit;
}
}
}