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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化