Results 1 to 4 of 4

Thread: how to check if user is logged in or not?

Hybrid View

  1. #1
    Join Date
    Jun 2013

    how to check if user is logged in or not?

    i have created a simple register and login system using phpmyadmin. On index.html page there are 2 divs. Left and right. On the right div there are 2 forms login and register. Register and login works fine. when user logs in, he is directed to another page.

    Now, after login if user comes to index.html page, i need to show him different options in the right div.. like. his dashboard, and more links to his personal account. To do that i changed index.html to index.php and added this code.

    <div id="left">
    left div content
    <div id=-"right">
    if(isset($_SESSION['email']) && isset($_SESSION['pass']))
    //show user some links to his account.
    //show login and register forms
    But it didn't work. how should i do this?

  2. #2
    Join Date
    Dec 2013
    Sydney, NSW Australia
    Is that the entirety of the page? If so, you need to add the session_start() function to the top of the file in order to access the session.

    Also, it would help to see the login script as well.

  3. #3
    Join Date
    Aug 2004
    If $_SESSION['pass'] is the user's password, I would recommend not saving it in $_SESSION to begin with, and of course then not checking for it to see if they are logged in. That's one less place a hacker might be able to steal passwords from.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #4
    Join Date
    Jul 2013
    Voorheesville NY USA
    #1 - I strongly agree with NogDog's suggestion of NOT posting a password in SESSION (!).

    MOst importantly thought - whatever do you mean by "it didn't work"? The script died? The php didn't perform as expected? No links showed up?

    BTW - try learning to write your code in separate html and php sections. Makes for much easier writing, reading, and understanding the code. Switching in and out of php mode is such a PIA when coding, when reading and when debugging. In this case, just create your html and place a php var in each div. Then in our php area, depending upon your if statements, assign content to the appropriate php var and then let your html (with embedded php vars) simply display the page.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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