dongqie5529 2011-11-28 01:57
浏览 175
已采纳

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

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. 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
  • 写回答

2条回答 默认 最新

  • duan7664 2011-11-28 02:10
    关注

    Make sure that you do not have any code echo'd out before or after the php tags. 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. Doing so will help avoid any extra spaces after it which will cause that error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记