4 Replies - 3362 Views - Last Post: 02 March 2012 - 11:24 PM Rate Topic: -----

#1 edisonlu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 26-February 12

How to check login status?

Posted 01 March 2012 - 09:32 PM

Hello everybody. Now I'm doing a web project and considering how to check the login status. I wonder if I can use both Javascript and PHP to finish this job or just using PHP. Actually, I have a idea that I can create 2 forms. For example, one form for people to login(display login and join buttons), another form for people who have already login(display user's basic information, and some buttons, such as logout and account buttons. Meanwhile, I use Javascript(if...else) to control which form will be shown, based on the login status. With this way, I must use PHP to check the session. however, I also can use PHP only to make this function.
Is my idea correct? Can anybody give me some tips about checking the login status?

In addition, if the user doesn't login, he can't create postings. Specifically, he can't click on the button and text area. On the text area, there is a label saying "login or register before posting". The form is just like the screenshot below:
Attached Image

How to do this effect? With Javascript or PHP or both techniques?
I'm looking forward to any clue and discussion.
Thanks a lot. :detective:

Is This A Good Question/Topic? 0
  • +

Replies To: How to check login status?

#2 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: How to check login status?

Posted 01 March 2012 - 10:31 PM

You can do this purely in PHP:


//Assuming $_SESSION["user"]["loggedIn"] is the user's session containing the login info

if(isset($_SESSION["user"]["loggedIn"])) {
    
    print "<form action='account.php' method='post'> <p>Form for the account management</p> </form>";
    
}else{
    
    //Display the login form

}



This post has been edited by xxxjj18: 01 March 2012 - 10:31 PM

Was This Post Helpful? 0
  • +
  • -

#3 edisonlu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 26-February 12

Re: How to check login status?

Posted 02 March 2012 - 09:34 PM

View Postxxxjj18, on 01 March 2012 - 10:31 PM, said:

You can do this purely in PHP:


//Assuming $_SESSION["user"]["loggedIn"] is the user's session containing the login info

if(isset($_SESSION["user"]["loggedIn"])) {
    
    print "<form action='account.php' method='post'> <p>Form for the account management</p> </form>";
    
}else{
    
    //Display the login form

}




Hello, do you mean that I don't need to use anything about Javascript to check login status?
Thanks.
Was This Post Helpful? 0
  • +
  • -

#4 xxxjj18  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 53
  • View blog
  • Posts: 167
  • Joined: 30-November 11

Re: How to check login status?

Posted 02 March 2012 - 09:51 PM

Yes this is what I mean.

I'd assume you're most likely handling the user's info with $_SESSIONs, so therefore there's no need for the Javascript.

How are you handling the user's info?
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2927
  • View blog
  • Posts: 10,114
  • Joined: 08-August 08

Re: How to check login status?

Posted 02 March 2012 - 11:24 PM

This is one of those questions where if you have to ask then you don't know enough about the language or writing code. Checking status is just a matter of using a conditional statement (ie, if(something) {...) but the real question is when to use it and what that something is. The answer depends on the structure of your code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1