doufei3152 2012-04-23 08:26
浏览 57
已采纳

登录状态指示灯功能不起作用

I have a login status indicator div on my ajax-php database's home page. The login button when clicked does two things.

<input value="Login" type="button" onclick='logIntheUser(/*function to process login request*/);updateLoginStatusIndicator(/*function to update login status in login staus indicator div*/);' />
  1. It calls a logIntheUser function to send the login data to the php access processor file to set $_SESSION['username'] if user name and password are correct.
  2. It also calls updateLoginStatusIndicator function which displays logged in as $_SESSION['username'] if $_SESSION['username'] is set or show "not logged in" if $_SESSION['username'] is not set.

Here is the controller code which is executed with updateLoginStatusIndicator function:

    /*===login status indicator/updater===*/

    if(isset($_REQUEST['change-login-indicator']))
    {
    if(!isset($_SESSION))
    {
    session_start();
    }
    if(isset($_SESSION['username']))
    {
    echo 'Logged in as:'.$_SESSION['username'];
     }
    else
    {
    echo 'not logged in';
    }

Now the problem is that some time the user is logged in successfully(i.e. $_SESSION['username'] is set) but still the second function updateLoginStatusIndicator displays "not logged in". The login status indicator does not work evey time. May be if the updateLoginStatusIndicator runs after the logIntheUser then it will update login status properly. But I don't know how to do it. Please help!

EDIT

When I call the function as callback i.e like: logIntheUser(updateLoginStatusIndicator()), it still does not not work(may be my call back method is incorrect). Then when I add set_time_limit(1); to the updateLoginStatusIndicator() function script to delay it for 1 second, it starts to work but its not the best practice to delay the script. Kindly help me how can i work it ou without delay so that updateLoginStatusIndicator() function executes only after the logIntheUser() function has finished executing. Please help.

  • 写回答

3条回答 默认 最新

  • douyou3619 2012-04-23 09:22
    关注

    logIntheUser() performs an AJAX request, right? Then the problem with updateLoginStatusIndicator() most likely lies in the fact that if gets called right after the logInTheUser(), not after the AJAX request's successfully finished. That is, it may get the user's status before it's been updated. You should call updateLoginStatusIndicator() in the callbacks for the AJAX request.

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

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器