繁体   English   中英

登录检查页面空白或不重定向

[英]Login check page blank or doesn't redirect

一开始,脚本运行正常。 我登录,登出,并且能够多次这样做。

现在,我不知道发生了什么。 页面最后为空白,如果它不是完全空白,则会显示一些html,但不会重定向。 然而,它正在登录我,因为我可以直接进入我应该被重定向到的页面,方法是在地址栏中键入它而不会被退回到登录页面(这有意义吗?)?

我知道它必须是关于我的会话,但我不完全理解。

这是登录检查脚本:

<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$uname=$_POST['uname'];
$pname=$_POST['pname'];

$uname = stripslashes($uname);
$pname = stripslashes($pname);
$uname = mysql_real_escape_string($uname);
$pname = mysql_real_escape_string($pname);

$sql="SELECT * FROM $tbl_name WHERE username='$uname' and password='$pname'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("uname");
session_register("pname");
header("location:index.php");
echo " '<h2>Continue to the donor list</h2><br /><br />

            <div id="login-box-name">
                Return to the login screen?
            </div>

            <div id="login-box-field">
            </div>

            <div id="login-box-name2"><a href="index.php"><img src="images/continue-btn.png" /></a></div>

            <div id="login-box-field2">
            </div>

            <br />

            <span class="login-box-options">

            </span>

            <br />
            <br />' ";
}
else {
echo " '<h2>Wrong Username or Password</h2><br /><br />

            <div id="login-box-name">
                Return to the login screen?
            </div>

            <div id="login-box-field">
            </div>

            <div id="login-box-name2"><a href="login.php"><img src="images/return-btn.png" /></a></div>

            <div id="login-box-field2">
            </div>

            <br />

            <span class="login-box-options">

            </span>

            <br />
            <br />' ";
}
?>

这些是我收到的错误:

[27-Nov-2011 17:52:59] PHP Warning:  Cannot modify header information - headers already sent by (output started at /home4/folder/public_html/ccc/check.php:2) in /home4/folder/public_html/ccc/check.php on line 35

[27-Nov-2011 17:52:59] PHP Warning:  Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

确保在php标记之前或之后没有任何代码回显。 我学会避免这种情况的原因之一是删除最终的?>标记,如果之后没有其他任何内容,或者页面是纯粹的PHP。 这样做有助于避免在它之后的任何额外空格,这将导致该错误。

如果您在check.php页面中使用include或require,请不要在index.php页面或其他包含页面中使用类似的标头。 此外,请确保在打开和关闭PHP标记<?php . . . ?>之前或之后没有任何空格<?php . . . ?> <?php . . . ?> <?php . . . ?>

暂无
暂无

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

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