dongtie0929 2012-05-09 15:24
浏览 54
已采纳

php中的页面重定向不一致

I have set the session on all pages in my admin panel like so:

session_start();

if(!isset($_SESSION['username']))
   header("Location: login.php?e=please+login+first");

This seemed to be working properly on all my pages, but now when I refresh my page or click on a link, the page automatically redirects to login.php. This seems to happen infrequently. I don't understand what is causing this problem

As an example, my menu bar is like:

home : doctors: hospitals:  feedback

If I am on hospitals.php, then after a few mins I click on feedback.php (or any other link) I get redirected to login.php. The next time if I again click on the link I will not get redirected

Here is my dologin.php code

$qry = "select * from admin where username='$uname' and password='$pwd'";
//echo $qry;exit;
$rs = mysql_query($qry,$con);
if($rec= mysql_fetch_array($rs))
{
  $_SESSION['username'] = $rec['username'];
    header("Location: index.php");
}
 else if (empty($uname))
{
     header("Location: login.php?e=Please+enter+username");
}
 else
 {
     header("Location: login.php?e=Invalid+username+or+password");
 }
  • 写回答

2条回答 默认 最新

  • dragon201401 2012-05-09 15:30
    关注

    EDIT: Replace your query:

    $qry = "select * from admin where username='$uname' and password='$pwd'";
    

    With this:

    $qry = "select * from admin where username='" . $uname . "' and password='" . $pwd . "'";
    

    Also replace your:

    session_start();
    

    with:

    if (!isset($_SESSION)) {
      session_start();
    }
    

    Recommendations: I would also recommend placing the content that is being reused from file to file in a PHP include such as header.php.

    PS: try accepting more answers, it helps motivate people to answer your questions. Also keeps the community alive.

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

报告相同问题?

悬赏问题

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