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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug