简体   繁体   English

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

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

In the beginning, the script worked fine. 一开始,脚本运行正常。 I logged in, logged out, and was able to do that a number of times. 我登录,登出,并且能够多次这样做。

Now, I don't know what's happened. 现在,我不知道发生了什么。 The page ends up blank and if it's not entirely blank, it shows some html but doesn't redirect. 页面最后为空白,如果它不是完全空白,则会显示一些html,但不会重定向。 However, it's logging me in because I can go directly to the page I'm supposed to be redirected to by typing it in the address bar without being bounced back to the login page (did that make sense)? 然而,它正在登录我,因为我可以直接进入我应该被重定向到的页面,方法是在地址栏中键入它而不会被退回到登录页面(这有意义吗?)?

I get that it must be something about my session, but I don't fully understand. 我知道它必须是关于我的会话,但我不完全理解。

This is the login check script: 这是登录检查脚本:

<?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 />' ";
}
?>

These are the errors I've received: 这些是我收到的错误:

[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

Make sure that you do not have any code echo'd out before or after the php tags. 确保在php标记之前或之后没有任何代码回显。 One why I have learned to avoid that is to remove the final ?> tag if there is not going to be anything else after it or if the page is purely PHP. 我学会避免这种情况的原因之一是删除最终的?>标记,如果之后没有其他任何内容,或者页面是纯粹的PHP。 Doing so will help avoid any extra spaces after it which will cause that error. 这样做有助于避免在它之后的任何额外空格,这将导致该错误。

If you using include or require in the check.php page, don't use similar header in index.php page or other included page. 如果您在check.php页面中使用include或require,请不要在index.php页面或其他包含页面中使用类似的标头。 Also, make sure you don't have any white space before or after the opening and closing PHP tags <?php . . . ?> 此外,请确保在打开和关闭PHP标记<?php . . . ?>之前或之后没有任何空格<?php . . . ?> <?php . . . ?> <?php . . . ?> . <?php . . . ?>

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

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