NSW42 Posted October 29, 2008 Share Posted October 29, 2008 heya, is there a way I can get the below code to use email address to login as well as the username. Regards <?php include("functions.php"); if(@$action=='login') { if($_COOKIE['username']=="" AND $_COOKIE['password']=="") { $md5_password = md5($_POST['password']); $sql = mysql_query("SELECT * FROM users WHERE username = '$_POST[username]' AND password = '$md5_password'") OR DIE("Sorry there is a mysql error."); $row = mysql_fetch_array($sql); $numrows = mysql_num_rows($sql); if($_POST[password]=="") { print("No password Entered."); login_form(); exit; } elseif($_POST[username]=="") { print("No username Entered."); login_form(); exit; } elseif($numrows == "0") { print("Username and Password doesnt match!"); login_form(); exit; } else { setcookie("username","$_POST[username]",time()+30000000); setcookie("password","$md5_password",time()+30000000); echo "<meta http-equiv=refresh content=\"5;url=/\">"; print("your now being logged in!"); } } else { echo "<meta http-equiv=refresh content=\"2;url=/\">"; print("Your are already loggedin!"); } } if(@$action=="") { login_form(); } ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/ Share on other sites More sharing options...
NSW42 Posted October 31, 2008 Author Share Posted October 31, 2008 just a bump Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679118 Share on other sites More sharing options...
waynew Posted October 31, 2008 Share Posted October 31, 2008 Delivery for OP. <?php include("functions.php"); if(@$action=='login') { if($_COOKIE['username']=="" AND $_COOKIE['password']=="") { $md5_password = md5($_POST['password']); $sql = mysql_query("SELECT * FROM users WHERE (username = '$_POST[username]' OR email = '$_POST[username]') AND password = '$md5_password'") OR DIE("Sorry there is a mysql error."); $row = mysql_fetch_array($sql); $numrows = mysql_num_rows($sql); if($_POST[password]=="") { print("No password Entered."); login_form(); exit; } elseif($_POST[username]=="") { print("No username Entered."); login_form(); exit; } elseif($numrows == "0") { print("Username and Password doesnt match!"); login_form(); exit; } else { setcookie("username","$_POST[username]",time()+30000000); setcookie("password","$md5_password",time()+30000000); echo "<meta http-equiv=refresh content=\"5;url=/\">"; print("your now being logged in!"); } } else { echo "<meta http-equiv=refresh content=\"2;url=/\">"; print("Your are already loggedin!"); } } if(@$action=="") { login_form(); } ob_end_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679269 Share on other sites More sharing options...
NSW42 Posted October 31, 2008 Author Share Posted October 31, 2008 heya, ok what that does, it says your logging in and and goes back to the home page as if you are, but when you go to a page to where only members can access, it stops as it says your not logged in. thats with using email login, but signs in fine still on username. Regards Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679654 Share on other sites More sharing options...
CroNiX Posted October 31, 2008 Share Posted October 31, 2008 You're storing a password in a cookie? Oh my... Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679677 Share on other sites More sharing options...
NSW42 Posted October 31, 2008 Author Share Posted October 31, 2008 lol heya cron, um yeh that be right as you can see, enlighten me more if you would like, as ive said many times on various psts here or anywhere else, im still very much new to php and still learning more and more, so if you have any suggestions or can help, please do as im all for learning Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679681 Share on other sites More sharing options...
revraz Posted October 31, 2008 Share Posted October 31, 2008 Probably because on your other page you are checking the COOKIE username and you need to allow for the email address there. Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679711 Share on other sites More sharing options...
NSW42 Posted November 1, 2008 Author Share Posted November 1, 2008 yes it not grabbing the cooking from somewhere, on login it actions to functions, but there isnt anything in functions to here function login_form() { global $siteurl,$sitetitle,$username; I added in $email if its correct, but same result, I know its a trivial thing from here on in, but im losted on it now lol Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679765 Share on other sites More sharing options...
NSW42 Posted November 1, 2008 Author Share Posted November 1, 2008 thought id just post the functions for login to see if maybe a clue lays there as to where its missing the cookie. Cheers function login_form() { global $siteurl,$sitetitle,$username; print(" <form action='$siteurl/login.php?action=login' method='post' name='l_form' onSubmit=\"document.l_form.l_submit.disabled=true\"> <table width='50%' border='0' align='center' cellpadding='4' cellspacing='0'> <tr> <td width='22%'>Username</td> <td width='78%'><input name='username' type='text'></td> </tr> <tr> <td>Password</td> <td><input name='password' type='password'></td> </tr> <tr> <td> </td> <td><input type='submit' name='l_submit' value='Login To $sitetitle!'></td> Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679799 Share on other sites More sharing options...
NSW42 Posted November 1, 2008 Author Share Posted November 1, 2008 Thanks to all that helped with this and doh me I forgot to check user check and add email in there as well. Many Thank Again Quote Link to comment https://forums.phpfreaks.com/topic/130569-solved-usernameemail-login/#findComment-679831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.