www.webdeveloper.com
Results 1 to 4 of 4

Thread: Check PHP session with jQuery

  1. #1
    Join Date
    Sep 2009
    Posts
    172

    Check PHP session with jQuery

    All,
    Is there a way to check to see if a user currently has a session in PHP with jQuery? I'm trying to say if there isn't a session then I'd like to pop open a login box which I can do but just don't know how to check the session. Thanks.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    If there is not a PHP session, you may simply echo/print the JavaScript codes you need (no matter if it is JQuery or anything else). The problems resumes to a PHP problem: what to echo and what not if a PHP session variable exists.

    But: it is not a wise thing to use a JavaScript (JQuery or whichever other JavaScript library - it makes no difference) code to display a login box or not. This has to be done only with the server-side language (PHP this case).
    Last edited by Kor; 03-15-2011 at 02:19 PM.

  3. #3
    Join Date
    Sep 2009
    Posts
    172
    Agreed, I would want to use the jQuery to use the .load function and call my PHP script to display the login box if there is no PHP session variable present.

  4. #4
    Join Date
    Jan 2009
    Posts
    3,346
    You can query a php script using AJAX that tells you whether the session has expired periodically and then load the form if the session is no longer valid. My recommendation is to use JSON in your returns from php since you could combine both calls into a single response.

    PHP Code:
    $resultsArray['status'] = false;
    $resultsArray['form'] = "html form for login here";
    if(
    $validSession){
        
    $resultsArray['status'] = true;
    }
    json_encode($resultsArray); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles