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

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?