PHP Tutorials: Register & Login: User login (Part 3)

Posted by: Admin  :  Category: Php

Linux Cpanel shared hosting: 600 GB disk space, 6 TB bandwidth, free domain, unlimited databases and ftp accounts, web hosting cheap and pro at Hostony

Linux Cpanel shared hosting: 600 GB disk space, 6 TB bandwidth, free domain, unlimited databases and ftp accounts, web hosting cheap and pro at Hostony

Part of the ‘Register & Login’ Project from PHP Academy. This tutorials walks you through how to process a username and password based login against details found in a database, set a session, and process a logout function.

Linux Cpanel shared hosting: 600 GB disk space, 6 TB bandwidth, free domain, unlimited databases and ftp accounts, web hosting cheap and pro at Hostony

25 Responses to “PHP Tutorials: Register & Login: User login (Part 3)”

  1. therichguardschannel Says:

    @midnight0094 change

    if($_SESSION[‘username’])
    {
    //code
    }

    to

    if(isset($_SESSION[‘username’]))
    {
    //code
    }

  2. borge947 Says:

    @huskbarful You should basically just remove whan of the equal signs “=” as it should SET a variable, not COMPARE it 🙂

    = is SET
    == is COMPARE

    Alex corrects this two minutes later as well!

  3. borge947 Says:

    @RS777able Not that advanced 🙂 in the form tags, just replace action=”login.php” with action=””, and move everything from login.php to the bottom of the index page.

    That’s what I usually do from the start, to avoid the information being passed around so much, especially when working with passwords that contain clear text. You should ALWAYS encrypt passwords with MD5 or similar.

  4. cyclograzzer1 Says:

    midnight – I had the same problem. I used
    if (isset($_SESSION[‘username’]))
    instead. Seems to work ok now.

  5. Acceptable76 Says:

    @huskbarful $_SESSION[‘username’]==$user­name;

    Not DBUsername, he corrected his mistake half way through the tutorials.

  6. RS777able Says:

    I love your tutorials!

    So every time someone will type in their wrong user name it gives you the error message on a different page. How will you be able to make the error message appear on the bottom or top of the log in form?

  7. TheGODsOPINION Says:

    Hi Phpacademy 🙂
    Thx for the great Tut! I created my Login with your Video Help.
    So how do I insert it in to a CSS Webpage (that I also already created) in Dreamweaver CS5?

  8. huskbarful Says:

    Hello, I get Notice: Undefined index: username in C:wampw wwTestlogin.php on line 29

    where I have this
    $_SESSION[‘username’]==$dbusername;

    what am I doing wrong?

  9. Phenom24gtr Says:

    @LewisAM37 This got me as well so i gave you code a go and it worked fine thanks

  10. LewisAM37 Says:

    @midnight0094

    i think i had the same problem as you

    i changed
    if ($_SESSION[‘username’])

    to
    if (isset($_SESSION[‘username’]))

    and that fixed everything, for me at least

  11. ffredson Says:

    @ael1988monsters

    No it is not, this is just a basic example.

  12. Bigturkz Says:

    @Tnargav same :D, this phpacadmy is brill 😀

  13. Tnargav Says:

    @Bigturkz

    I’ve just used isset in if statement and the error is gone, try it.

  14. Bigturkz Says:

    @Tnargav sorted it, replace $_session etc etc with (isset($_SESSION[‘username’])) after “session_start();

  15. Tnargav Says:

    @Bigturkz

    got the same error message 😉

  16. Bigturkz Says:

    Notice: Undefined index: username on line 11 :S

  17. arnisjutsus Says:

    i can log in even in wrong password, can some one teach me how to correct this error?

  18. arnisjutsus Says:

    @guitarockdude DUDE thank you, can you please teach me why, i can log in even in wrong password? i will subscribe to your channel 🙂

  19. robert0455 Says:

    @stuckUPstudios , this has been a while now but this works
    header( ‘Location: yourwebsite/member.php’ ) ;

  20. excanator Says:

    @stuckUPstudios Oh forgot to tell it has to be between php tags

  21. excanator Says:

    @stuckUPstudios Use header(“Refresh: 2;url=member.php”); just place that at row 1 of your script. Works for me 😉

  22. PeterLifeOnline Says:

    @guitarockdude Thanks a lot!!

  23. guitarockdude Says:

    @PeterLifeOnline replace with (isset($_SESSION[‘username’]))

  24. PeterLifeOnline Says:

    Notice: Undefined index: username in C:xampphtdocsc4phploginsessionmember.php on line 5
    please, we don´t know what is wrong… someone….

    nice tut by the way!

  25. TheSteveAndJokerShow Says:

    i got this:

    “Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9558847/public_html/login.php on line 20”

    what did i do? o.O

Leave a Reply

*