php - Login not persisting across pages -
Hello I have created a login system for my website dubleeble.com and for some reason when you login You keep on logging in on one page but when you go to another page you log out of it! How do I fix it?
This is the code I used to:
& lt ;? Php session_start (); $ Username = $ _POST ['user']; $ Password = $ _POST ['pass']; If ($ username and amp; $ password) {$ connect = mysql_connect ("host", "user", "pass") or die ("can not connect!"); Mysql_select_db ("db"); $ Query = mysql_query ("Choose user WHERE user name = '$ user name' '); $ Numrows = mysql_num_rows ($ query); if ($ numrows! = 0) {while ($ row = mysql_fetch_assoc ($ query)) {$ Dbusername = $ line ['username']; $ dbpassword = $ line ['password'];} if ($ user name == $ dbusername & amp; $ password == $ dbpassword) {$ _SESSION ['user Name '] = $ user name; header (' location: '$ _SERVER [' HTTP_REFERER ']);} and header (' location: http: //dubleeble.com/php/login/incorrect.php '); } And header ('location: http: //dubleeble.com/php/login/incorrect.php');} and header ('location:' $ _SERVER ['HTTP_REFERE R ']);? & Gt;
Notes:
- Log in 'Login' is the login ...
- You should use some types of password encryption, instead of just storing text values you should
Use mysql_real_escape_string as I did to make sure that SQL injection is not possible -
Make sure that you have sessio on every page that uses your session variable N_start () are saying $ username = $ _POST ['user']; $ Password = $ _POST ['pass']; If (isset ($ username) & amp; amp; and isset ($ password)) {$ connect = mysql_connect ("host", "user", "pass") or die ("can not connect!") ; Mysql_select_db ("db"); $ Row = mysql_fetch_assoc ("Select * user WHERE user name = '" .mysql_real_escape_string ($ user name). "' '); $ Numrows = mysql_num_rows ($ line); If ($ numrows & gt; 0) {if ($ username == $ row ['username'] & amp; $ password == $ row ['password']) {session_start (); $ _SESSION ['username'] = $ username; Header ('location:' $ _SERVER ['HTTP_REFERER']); } And header ('location: http: //dubleeble.com/php/login/incorrect.php'); } And header ('location: http: //dubleeble.com/php/login/incorrect.php'); } And header ('location:' $ _SERVER ['HTTP_REFERER']);
Comments
Post a Comment