Added: 3 years ago
From: phpacademy
Views: 111,729
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:
see all

All Comments (453)

Sign In or Sign Up now to post a comment!
  • HI, just one problem i am facing, once i login 'you are in! and proceed to the members page, i keep getting 'You must be logged in! ' instead of 'welcome message'

    what could be causing this to happen?

  • thank you very much for your great tutorials ,, and i like when u make mistakes in the(only in the tutorials ) so we learn from them and how to avoid them. Greetings

  • i updated the php and now its ~~OK

  • Comment removed

  • if anyone is having issues with including html the session_start(); must be before the html tags!

  • If you had any of the problems above, don't forget to call the session_start(); functon in the beginning of the login page!

  • Is there a way to make the username part work for both upper and lower case, for example if my username were robert if you entered Robert it would work as well?

  • I have typed the code and sent me back 2 warnings :

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\login\member.p­hp:67) in C:\xampp\htdocs\login\member.p­hp on line 69

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\login\member.p­hp:67) in C:\xampp\htdocs\login\member.p­hp on line 69

  • me 2

  • Why does it display "1" when it should display my username..I have nothing telling the script to gather an integer..I took out the echo statement getting how many users were in the database..what am I doing wrong?

  • Comment removed

  • nice verry nice

  • Dear when I reach to the $_SESSION['username']==$dbuser­name;

    It gives an undefined error in preview.. like

    "NOTE: Undefined index: username in C\xampp etc..

    kindly solve my problem...please

  • when i type in the wrong password, it says that the user doesn't exist... why?

  • so how do we allow users to register

  • can i download the code from anywhere?

  • @stephensansatymail It is good practise to write your own code. Gets you to digest what is happening and to think about the flow of the program.

  • Amazing videos by the way, I'm subscribing to you!

  • If you don't practice regularly, PHP can be easily forgotten. But this dude is really awesome

  • Comment removed

  • Comment removed

  • 3:47

    i was happy coz my username displayed on the screen and he's not LOL

  • hey ive tried everything to get the username to come up on members page someone plz help

  • This worked for me to fix the "Undefined index" issue in member.php is to change

    if ($_SESSION['username'])

    to

    if (isset($_SESSION['username']))

  • @TheRissk13 cheers man, this was the only bugger i had, but all is good now thanks to that wee tip! This guy is really helpful though, I mean before I was just using the book php & mysql for dummies :P this guy know's what he's talking about. But yeah once again cheers! Appreciate the help!

  • @TheRissk13 Thanks.

  • @TheRissk13 If only I'd have read the comments 3 fruggin hours ago.... WTF...over!

  • To everyone who's having issues with the "Undefined Index" issue, in the 'member.php' page, where you see "if ($_SESSION ['username'])" just remove the ['username'] part. So line 5 should look like this:

    if ($_SESSION)

  • I get this notice on member page when looking back when logged out. Notice: Undefined index: username in C:\xampp\htdocs\member.php on line 5 :( HELP

  • @rainbowcrak I have the same problem :(

  • very helpful..tnx :)

  • I am also getting the Undefined index message

    Other than that it is working

    Also on the member.php do I need to put all text html and all in the echo statement

    Thanks

  • I have a problem. I have a member page with a link back to login.php, and when I click that it says "Please enter a username and a password" instead of what I wanted it to say. What is the problem??

  • After 10 minutes of missing that you wrote "logout" at the end. I finally found that was the problems. I am so stoopid.

  • hope someone answers this:

    I didn't get why did he check in the if statement if the username and password match ??

    If they already fetched from the database that mean they are exist !

  • HELP!! after logging out and going back to member.php, i have this error:

    Notice: Undefined index: username in C:\xampp\htdocs\login\member.p­hp on line 4

    What could be wrong?

  • @DarlingBryan tried everything and I'm still getting it

  • @AbhishekPratapa there's a tutorial on how to remove the errors but i cant understand alex didnt have the error

  • @DarlingBryan Same, have you found a solution?

  • I keep getting this message :/ "Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent."

  • kj;h

  • THIS LAST CODE

    4. if ($_SESSION['firstname'])

    it gives me an error

    Notice: Undefined index: firstname in C:\xampp\htdocs\123\member.php on line 4

  • @MyStada me too man and it's kind of annoying on there

  • @AbhishekPratapa fot that i use now

    error_reporting(E_ALL ^ E_NOTICE);

    ;-)

  • Comment removed

  • How do i make it so that when the user logs in, instead of saying "Welcom, Alex!" in a PHP page it says it somewhere in my current HTML page?

  • hi. great video. Can you also put up a tutorial on how to manage different user groups and then give specific page access rights to the users based on the logged in user.

  • where is the register page? ..that's the complicated bit for me..

  • Once i have logged in and logged out and have typed in member.php in the browser...it does say I must be logged in however i still get this error

    Undefined index: username in member.php....WHAT DO I DO?

  • I still get Notice: Undefined index: username in and I have set the $_SESSION[''username] = $dbusername;

    also did

    $_SESSION[''username] = $username;

    Ideas?

  • @philykearney $_SESSION['username']=$dbusern­ame;

  • @philykearney

    $_SESSION[''username] = $dbusername;

    should be this exactly

    $_SESSION['username'] = $dbusername;

  • I have one problem on firefox. If I destroy the session and then go to member.php I get an error which I believe comes from the IF sentence saying "Notice: Undefined index: username in *member.php* on line 8" can I actually check the session while it's not existing?

  • @ighnaz Same, have you found solution?

  • @rainbowcrak yep I've fixed it but I don't really remember it anymore, if you post me the code I can take a look

  • Thank you so musch! You are so good! I´ve learned so musch during your videos!

  • You are in! Click here to enter the member page.1

    It gives me the above message with a number 1 at the end. Why?

    Thanks

  • @MegaTony1965 You still have the line " echo $numrows; " that was removed in Part 2 at 4:58 :-)

  • thank you very much, great tutorial keep up the good work!!!

  • this really anoying error is coming up can you help me??

    Notice: Undefined index: username in C:\xampp\htdocs\phptests\membe­r.php on line 5

    you must be logged in

  • @PellyTravispell

    If you have a username and  password make sure to include that...

  • First of all excellent tutorial.

    I followed step by step and reach the same results using the wampserver.

    now when I went up these files to the web / page did not recognize the session.

    there is some configuration that has to do with the browser for the session Acknowledge me?

  • You can use this code 

  • gr8 tutorial bro!

  • Ok take a look everyone at afflicto,dreamvoid,com :) I followed this tutorial. I stayed up all night. looks pretty cool IMHO =D

  • If you are having the Notice: Undefined index

    I got a simpler solution.... instead of

    $_SESSION['username']==$dbuser­name;

    use

    $_SESSION['username']=$dbusern­ame;

    That should work

  • @himes19 COOL THANKS DUDE

  • thanks men!! It's really a great help. :D

  • Comment removed

  • i followed everything youve done and type and i get this error message

    log in successful

    click here to enter member page>

    Notice: Undefined index: username in C:\xampp\htdocs\login.php on line 35

  • @manasume

    In your login.php:

    Instead of

    $_SESSION['username']==$dbuser­name;

    do

    $_SESSION['username']=$usernam­e;

  • @manasume I have the same problem, help please

  • I want to get directed to the member.php page imediately when I click the login button.....Why should I use "Click" here to enter member page??

  • Comment removed

  • @Jangain

    echo "You're logged in! You'll be redirected to members page";

    $_SESSION['username']==$dbuser­name;

    header( 'refresh: 3; member.php' );

    // 3 are the seconds to redirect you =)

  • can somebody message me a code that redirects me to the index.php if i'm nit logged in?

  • @mehdolino1999

    after the session_destroy();, you put header('location: index.php')

  • @ruthwijma

    thanks

  • Is this secure? The code doesn't seem solid :S

  • WHO CAN HELP ME?

    if i put the sesstion start on the top of my page code, the user name and logout appers on the top of my website... so how can i move the username and logout text to another place??When i make a div and put in css margin-top:100px; the whole page goes 100px down??

    thx:(

  • Comment removed

  • Hi, I followed closely this tutorial but I can't seem to get "session_start" to work. It always display this warning message:

    Warning: session_start() [function.session-start]: open(/var/chroot/home/content/­28/8192128/tmp/sess_60fin04a25­i4i76lb2ls3s8i91, O_RDWR) failed: No such file or directory (2) in /home/content/28/8192128/html/­user/login.php on line 3

    Help, anyone? Thanks.

  • Hi, I followed closely this tutorial but I can't seem to get "session_start" to work. It always display this warning message:

    Warning: session_start() [function.session-start]: open(/var/chroot/home/content/­28/8192128/tmp/sess_60fin04a25­i4i76lb2ls3s8i91, O_RDWR) failed: No such file or directory (2) in /home/content/28/8192128/html/­user/login.php on line 3

    Help, anyone? Thanks.

  • Isn't it better to make your logout page like this?

    session_start();

    session_unset();

    session_destroy();

  • can u like have the codes available cant see the entire code properly...

  • Comment removed

  • Help me please, ive done something wrong. In the wrong password message and the Youre in message it says 1 in the end and when i click on the Click link it says Welcome, 1 instead of my name. Whats wrong? Send me a message if ou want to see the code, i couldnt write it, too many charaters

  • Comment removed

  • Comment removed

  • if this helps anyone. when he does $_SESSION['username']==$dsuser­name;, use this insead. $_SESSION['username']=$dbusern­ame;. using the == only works in if/else statements

  • Hi, I''ve got a problem. I'm running this code during HTML 5 on Adobe Dreamweaver CS5

    This is my line of code:

    $connect = mysql_connect("localhost", "root", "") or die("Unable to connect!");

    mysql_select("phplogin") or die("Couldn't find db (database)");

    $query = mysql_query("SELECT * FROM users WHERE username='$username'");

  • @Kevco1808 thanks so much :) :):) :):) :):) :)

  • I am getting this error

    Notice: Undefined index: username in C:\xampp\htdocs\member.php on line 6

    you must be logged in.

    I have checked the user name is is small letters only in member.php and all other pages but its showing as undefined index don't know why.

    can any one help me

  • Comment removed

  • Comment removed

  • Comment removed

  • Please help the session part doesn't work!

  • up to about 4:34 on the video, when i login onto the member page then go back to the login.php i get this

    Notice: Undefined index: username in C:\xampp\htdocs\loginsession\l­ogin.php on line 5

    Notice: Undefined index: password in C:\xampp\htdocs\loginsession\l­ogin.php on line 6

    Please enter a username and a password!

  • To logout instead of session_destroy() you can also use unset($_SESSION['username']);

  • Hello ! great tutorial ! but I have a little problem with the session_start(); it returns me tis error Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /Applications/XAMPP/xamppfiles­/htdocs/xampp/phplogtest2/logi­n.php:12) in /Applications/XAMPP/xamppfiles­/htdocs/xampp/phplogtest2/logi­n.php on line 14 any idea ?

  • @HorizonEW and this

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Applications/XAMPP/xamppfiles­/htdocs/xampp/phplogtest2/logi­n.php:12) in /Applications/XAMPP/xamppfiles­/htdocs/xampp/phplogtest2/logi­n.php on line 14 why this happens ?

  • Comment removed

  • Thanks! All these login tutorial help me a lot :D

  • unfortunately this isnt very secure, 'cause to see all the content you just have to declare a $_SESSION['username']. in "the real world" you would need to check the content of S_SESSION['username'] against the db every single time (one time per page). i would create 3 sessions, 1) $username 2) hashed($password) 3) salted($username . $password). look up what "salt" and "hash" (md5, SHA etc.) means. you have to forbid access to a user, when he/she just creates sessions. sorry for my english ;)

  • If you had the same "Notice: Undefined index: username in ..." error that drove me bonkers, this is how I dealt with it:

    instead of " $_SESSION['username']==$dbuser­name;"

    I used " $_SESSION['username']=$dbusern­ame;"

    It works just the same and you don't have to suppress errors.

  • @Tafaer gettt it really works..

    thnx

  • Good tutorial. Also im not find the register?!?

  • i got error on the member(.)php..

    it's still showing Welcome !.. what's my error?.. i tried using $_SESSION['username']=$usernam­e; it doens't work.. XD

  • dont die =[

  • This is not working for me!!!! help!!!! when i insert a code nothing appear!

  • Ok everything is good except that when I log in how do I hide login.html because It shows the login dialog again and when I go to login.php manually it says the enter username and pass error

    How do I make it show you are logged in or something when they manually go there?

  • if i'm not logged in .. what is the code so that it will redirect me to the index page???

  • 8:15 Notice: Undefined index: username in C:\xampp\htdocs\member.php on line 5

    You must be logged in!

    Can someone correct me please! thanx.

  • @gentlxman try if (isset($_SESSION['username']))

  • @bossco30 It works Thanx so much !

  • ha,ha, "i´m gonna want to die"...I usually think that about crossbrowser compatibiliity, not about php.

  • instead of "you must be logged in" you could use a header which redirects you to the index.php file

  • thanks for the tutorial!! i had many problems while doing this but i finaly made it :D now over to "change password" tutorial... hope that will be easier xD

  • i solved it :)) i was trying to access localhost/proiect/login.php first.  The point is you must put localhost/proiect/index.php . Log in , and it should work.

  • Notice: Undefined index: username in C:\xampp\htdocs\proiect\login.­php on line 5

    Notice: Undefined index: password in C:\xampp\htdocs\proiect\login.­php on line 6

    Please enter a username and a password

  • @hantataru Had it too. Be sure you watched the whole tutorial before you ask anything. It helps ;)

  • got stuck on member php

  • could you send me a copy of the codes for all of this because I've done this 5 times and nothing is happening

  • I learnt alot but wat if the login form is on the index page the concatenation wud show an error til the person actually login. so wat can i do so that error wud not show or the error would not actually be an error?hope u get wat im asking

  • thanx man your the best

  • I've followed your tutorial from step1 to this final stage. Thanks, it works perfect just like I wanted it. But I seem to have a little problem: I don't know how to direct the php script to my webpage when the visitor successfully log in.Please any one with you useful information should kindly post it here.Thanks

  • I must say unlike the rest, it was clear and straight forward for a complete beginner like me. 2 Thumps UP!

  • Comment removed

  • i have this ERROR MESSAGE

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\Myworks\login.­php:10) in C:\xampp\htdocs\Myworks\login.­php on line 11

    please HELP...

  • success! thx alex

  • oka everyone wh gets those notices IT IS NO ERRORS but the sure look ugly on the page to get rid of them ad this error_reporting(0); to the start of your code it will stop them fgrom showing up

    thumbs up so ppl see

  • @pakmand Noob. Thanks

  • @MrMobinga

    what are you doing here?

    you need to shut the fuck up and let people share.

  • @THE16THPHANTOM STFU You son of a bitch!!!

  • Thanks for your help dude! AWESOME VIDEO!!

  • Stuck. I have check my code again and again. Can't seem to find the error I'm getting. After I click the "click here" I get an error on the member.php page:

    Notice: Undefined index: username in ******member.php on line 5

    Welcome, ! < Username doesn't show either. Any ideas?

  • @spikey79 this from elsewhere, might help:

    PHP is case sensitive. The name attributes of your form elements are Name, Email, and Message. Consequently, you should be using $_POST['Name'], $_POST['Email'], and $_POST['Message'].

    "Undefined index" means the variable you are trying to use doesn't exist. $_POST['Name'] and $_POST['name'] are completely different variables. They may look the same to you, but not to PHP.

  • U r such a talent teacher for me, i have spent a lot of money to learn php ,but it was worthless..now i learn a lot from u ..keep going

  • i get a error on login.php with my connection to my phpmyadmin

  • I am having problems I typed the code in properly. and I can log on but when i click the link to enter the member page, it says please log in... it seams as tho echo $_SESSION['username']; works in login.php but not for member.php

    I have spent a long time on this if anyone can help that would be great

  • @18kitkats

    instead of

    echo "correct blabla and the link";

    make it:

    header("location: member.php");

    like if this works!

  • my server has session autostart set... causing havoc!

  • plssssssss help

    this is the error undifined??? $_SESSION['username']==$dbuser­name;

  • @killerboduk999 You have used double equality signs.

    Wrong:

    $_SESSION['username']==$dbuser­­name;

    Correct:

    $_SESSION['username']=$dbuser­­name;

  • @SimonAlling thanks man i will try it right now

  • @killerboduk999 No problem. I've done the same error the other way around many times when I've been writing JavaScript code. I've for example typed something like this:

    if (x = y) { randomFunction(); }

    (There should be two "=" as it is a comparison.)

  • @SimonAlling yeah thats right it must be (x==y)

    btw are you still in college??

  • @killerboduk999 No, I guess I'm in high school. :P

  • @SimonAlling how old are you?

  • @killerboduk999 17. Why? :-)

  • 2:00 I'm so proud of myself. ^^ I actually spotted the double equality signs and typed only one myself (and it worked). At 3:45, when my suspicion was confirmed to be correct, I was like "Yes!" :-)

    Don't get me wrong, though. Your tutorials are GREAT! I knew very little about PHP before I started watching them, and ... I don't know what to say. You're simply awesome!!!

  • Thanks, i've been trying for SOO long to find a good one of these tutorials! i'll be using many more of your videos!

  • 7:25 "Else, I'm gonna want to die" xD

  • Thanks so much for these videos!

    Just wondering, is it possible to automatically redirect the user to a members page when they put in the correct details, instead of showing the "You're in..." message?

    How would that be done?

  • Hey thanks for the upload,

    Just wondering about security, how would I be able to code it so that when I login that I cannot access the same page from a different browser, without logging in on that? thanks

  • great tutorial, it has been a great help...in a futur update could you code an automatique redirection from login.php to members.php instead of placing a link inside the login.php ....Thanks !

  • Comment removed

  • great tutorial..thank you phpacademy

  • midnight - I had the same problem. I used

    if (isset($_SESSION['username']))

    instead. Seems to work ok now.

  • 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?

  • @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.

  • 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?

  • Hello, I get Notice: Undefined index: username in C:\wamp\w ww\Test\login.php on line 29

    where I have this $_SESSION['username']==$dbuser­name;

    what am I doing wrong?

  • @huskbarful $_SESSION['username']==$user­n­ame;

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

  • @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!

  • Notice: Undefined index: username on line 11 :S

  • @Bigturkz

    got the same error message ;)