Sonia
Sonia

Reputation: 253

Can i check if a session is active throught the code instead at page load?

I remember that a question related to the session requiere a code placed above the page, before any kind of html result. Assuming that session_start() is correctly placed above, can i call the "is_Logged" function throught the body of the page?

In other word i've an admin panel with some option accessible without change the page. The risk is that the user could click on the options box while his session is expired, so for every "click" i've to check if it's still active.. Can i use the is_Logged function, or it's necessary to do an AJAX call?

UPDATE: What i mean is something like this

//some html code

    $('#impostazioniAccount').click(function(e){ 
       parent.location.hash = "sezioneImpostazioniAccount";

       <?php if(!isLogged())
       {
         header("location:../main/");
         exit;  
       }

    function isLogged()
    {return $_SESSION['user'];}

 ?>

Upvotes: 0

Views: 124

Answers (1)

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 174957

Yes, check your session_id(). If it returns an empty string, session is not set. If you want to be able to tell from the client-side, you'll need to use AJAX.

Upvotes: 1

Related Questions