繁体   English   中英

PHP标头(“ Location:url.php”)在godaddy中不起作用

[英]PHP header (“Location: url.php”) not working in godaddy

美好的一天。 我有关于标头的问题(“ Location:url.php”); 在PHP中。 我使用Macromedia Dreamweaver MX 2004编写了代码。所有标头在localhost服务器中均能正常工作,但是当上载至godaddy服务器时,登录后在没有错误的情况下重定向停留在(login.php)页面中。 在这里,我提供了文件(表单和PHP文件),并真的希望所有对此问题有疑问和知识的人都能对我有所帮助。 我真的不知道问题的原因是什么。 是因为代码吗?

还是因为会议?

还是因为UTF-8编码?

我确实在Dreamweaver中将页面的属性从西欧更改为UTF-8,但未选中BOM签名。 非常感谢您的帮助。 提前致谢。

这是(adminlogin.php)

<?php
session_start();
include('conn.php');
if(isset($_SESSION['username']) && isset($_SESSION['password']))
{ header("Location: admin.php");} 
?>
<html>
<head>
<title>Admin Login</title>
<style>
#popUpYes
{
    width: 60px;
    height: 25px;
    background-color: white;
}
#popUpYes:hover
{
    background-color: #D4A017;
} 
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h2><font color=gold> Admin Login </font></h2>
<form method = "post" action = "login.php" >
<table>
<tr>
    <td> <font color=silver>Admin ID</font></td>
    <td>:</td>
    <td><input type="text" name="username" size=20 ><br></td></tr>
    <tr>
    <td> <font color=silver>Password </font></td>
    <td>:</td>
    <td><input type="password" name="password" size=20><br></td>
</tr>
<tr>
</table>
<input type = "hidden" name = "submit">
<input type = "submit" name = "submit" value = "login" id="popUpYes" >
<input type = "reset" name = "reset" value = "reset" id="popUpYes" >
</form>
<body background="c.png" bgproperties="fixed">
</body>
</html>

这是(login.php)

<html>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<?php
session_start();
include('conn.php');
if($_REQUEST['username']=="admin" && $_REQUEST['password']=="abc123")
{
    $_SESSION['username'] = "admin";
    $_SESSION['password'] = "abc123";
    header("Location:admin.php");
}
else{ ?> <script> 
    alert ( "Wrong combination of Username and Password. Please try again.");
    </script> <?php
    header("Location:adminlogin.php");
}
?>
<body background="c.png" bgproperties="fixed">
</body>
</html>

这是(admin.php)

<?php
session_start();
include('conn.php');
if(!isset($_SESSION['username']) || !isset($_SESSION['password']))
{ header("Location:adminlogin.php"); }
?>
<html>
<head>
<style type="text/css">
a.button:hover
{
    background: #D4A017;
} 
</style>
<style> 
#pop
{
    width: 60px;
    height: 25px;
    background-color: white;
}
#pop:hover
{
    background-color: #D4A017;
}  
</style>
<title>Admin Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<form method = "post" action = "verification.php">
<br>
<h2><font color=gold>Admin Options: </h2><br></font>
<font color=white><b>
<input type ="radio" name="user" value="register">Click Here To Register An Agent<br>
<input type ="radio" name="user" value="regsales">Click Here To Create New Sales Record<br>
<input type ="radio" name="user" value="view">Click Here To View Agent Details and Sales<br>
<input type ="radio" name="user" value="edit">Click Here To Edit Agent Details and Sales<br></b>
<br><br>
<input type = "hidden" name = "verify"><br>
<input type="submit" name="submit" value="submit" id="pop">
<input type="reset" name="reset" value="Clear" id="pop"><br>
</font>
<body background="c.png" bgproperties="fixed"> 
<button><a class="button" href="logout.php" >Logout</button></a>
</body>
</html>

这是(conn.php)

<?php

$link = mysqli_connect('domain', 'username', 'password','databaseName') or
 die(mysqli_error());

?>

我也有这个问题。 只需使用ob_start(); 在脚本顶部的多个标题中。

ob_start()函数将所有服务器输出缓冲到字符串变量。 这样,您就可以在代码中的任何地方操作HTTP标头。

好吧,据我所知,答案很简单。

header()手册页所述,您不能在函数调用之前发送任何内容。 删除php块上方的html,然后将其移至其他位置,代码应该可以正常工作。

此外,如@DainisAbols的注释中所述,您应该使用die()exit() (它们都做相同的事情)以防止进一步执行脚本。

编辑:

在您的login.php页面中,您具有以下代码:

<html>

<body> <!-- 
            Right here, you have content, above your header() call.  Because this
            content exists, the headers for the page have already been sent, and 
            thus, they cannot be sent again by header().  You need to move this
            block of html to after your php script, so that the first line in
            your file is the opening php tag: (<?php), with nothing before it
       -->

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

<?php

session_start();

您没有在登录时进行重定向,因为在尝试在login.php中发送位置标头之前,由于呈现了html而已发送了标头。 将文件顶部的标记移到else子句中,这样就可以解决问题(假设没有其他潜在的问题)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM