header(location:someurl.php)无法在在线服务器上运行

时间:2014-02-03 10:43:37

标签: javascript php jquery html mysql

header(location: agentverification.php)在上传到godaddy服务器时不起作用,因为它在localhost服务器上运行。我尝试编辑我的代码但结果仍然相同。如果你们中的任何人能帮助我,我会很感激并提前感谢。

agentlogin.php

<form method = "post" action = "agentverification.php" >

<table>

<input type="text" name="ID" size=20 ><br></td></tr>
<tr>
<td>Password <font color=red>*</font></td> 

<td><input type="password" name="pass" size=20><br></td></tr>

</table>
<input type = "hidden" name = "login">
<input type = "submit" name = "login" value = "submit" id="pop">

agentverification.php

<?php

session_start();


$link = mysqli_connect('localhost', 'root', '','db5') or die(mysqli_error());

if(isset($_POST['login']))

{
extract($_REQUEST);

$id = $_POST['ID']; 

$pass = $_POST['pass'];


$query= "SELECT * FROM agentReg WHERE AgentID = '$id'";

$record = mysqli_query ($link,$query);


                $check=FALSE;

                while($row=mysqli_fetch_array($record))
                {
                    if($id === $row['AgentID']&& $pass === $row['password'] )
                    {
                        $check=TRUE;
                    }
                }


                if($check == TRUE)
                {
                    $_SESSION['AgentID'] = $id;
                    $_SESSION['password'] = $pass;
                    header("Location: agentpage.php");
                }
                else 
                { ?> <script> 
                alert ("Wrong combination of ID and Password. Please try again.");
                </script> <?php
                    session_destroy();
                    header("location: agentlogin.php");
                }

}?>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>

agentReg 数据库结构

CREATE TABLE agentReg
(AgentID varchar (100) primary key,
password varchar (100));

2 个答案:

答案 0 :(得分:1)

打印输出后,您无法使用header('Location: ...');

在您的上篇else中,您应该只包含session_destroy();,例如header('Location: agentlogin.php?error=idpassword');。错误消息应位于agentlogin.php

答案 1 :(得分:0)

使用

  

window.location.href ='http://www.google.com'; //会带你去谷歌。