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条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)