localhost Posted May 29, 2006 Share Posted May 29, 2006 I need a login script, I finally got my registration working..it uses md5 encryption. So I'll need a user and pass field and it has to change to md5 before it goes through to the database. I need it to use cookies and I would prefer only 1 cookie be set upon login. I have absolutely no idea how to go upon this...table name - usersconnect - inc/connect.phprow - usernamerow - passIf someone could just give me the basic maybe I could try and get it working and post back for help.Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/10670-login-script/ Share on other sites More sharing options...
ToonMariner Posted May 29, 2006 Share Posted May 29, 2006 have a look for the set_cookie function - its dead easy Quote Link to comment https://forums.phpfreaks.com/topic/10670-login-script/#findComment-39815 Share on other sites More sharing options...
legohead6 Posted May 29, 2006 Share Posted May 29, 2006 [!--quoteo(post=377936:date=May 28 2006, 07:18 PM:name=localhost)--][div class=\'quotetop\']QUOTE(localhost @ May 28 2006, 07:18 PM) [snapback]377936[/snapback][/div][div class=\'quotemain\'][!--quotec--]I need a login script, I finally got my registration working..it uses md5 encryption. So I'll need a user and pass field and it has to change to md5 before it goes through to the database. I need it to use cookies and I would prefer only 1 cookie be set upon login. I have absolutely no idea how to go upon this...table name - usersconnect - inc/connect.phprow - usernamerow - passIf someone could just give me the basic maybe I could try and get it working and post back for help.Thanks![/quote]Id recommend sessions! there easier!...lol.... Quote Link to comment https://forums.phpfreaks.com/topic/10670-login-script/#findComment-39822 Share on other sites More sharing options...
localhost Posted May 29, 2006 Author Share Posted May 29, 2006 What are the advantages and disadvantages between sessions and cookies?I'm still new to PHP...so by looking up some cookie stuff I was able to code this...but I know it won't work I just need to know what I have to do to make it work...[code]<?phpinclude('inc/connect.php');$uname = $_POST['uname'];$pass = $_POST['pass'];$chkpass = md5($pass);$query = "SELECT * FROM users WHERE username==$uname"$result = mysql_query($query) or die('Failed to connect to user database');$value = '$_COOKIE["Pranksters"]';setcookie("Pranksters", $value);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10670-login-script/#findComment-39824 Share on other sites More sharing options...
localhost Posted May 29, 2006 Author Share Posted May 29, 2006 Anybody?EDIT - I've added the form on the bottom, code here:[code]<style type="text/css"><!--.style3 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small;}--></style><span class="style3">Username: <input type="text" name="uname"><br>Password: <input type="password" name="pass"><br><input type="submit" name="submit" value="Login"></span>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10670-login-script/#findComment-39842 Share on other sites More sharing options...
localhost Posted May 29, 2006 Author Share Posted May 29, 2006 bump Quote Link to comment https://forums.phpfreaks.com/topic/10670-login-script/#findComment-39910 Share on other sites More sharing options...
localhost Posted May 29, 2006 Author Share Posted May 29, 2006 Here's my current code:[code]<?phpsession_start();ob_start();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Login - Pranksters</title><style type="text/css"><!--.text { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small; color: #666666;}#form1 #username { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #666666;}body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;}--></style></head><body><form id="form1" name="form1" method="post" action=""> <table width="59%" border="0" cellspacing="3"> <tr> <td>Username: <br /> <input name="username" type="text" id="username" /></td> </tr> <tr> <td>Password: <br /> <input name="password" type="password" id="username" /> <br /> <span class="text"> <input name="remember" type="checkbox" id="remember" value="yes" />Keep me logged in on this computer </span> <br /></td> </tr> <tr> <td><input name="Login" type="submit" id="username" value="Submit" /></td> </tr> <tr> <td><?php //Include Connection File include('inc/connect.php'); //If login is pressed if(isset($_POST['Login'])) { // Get the user info $username = strip_tags($_POST['username']); $password = strip_tags($_POST['pass']); $user = addslashes($username); $pass = addslashes($password); $md5pass = md5($pass); // Get the date $date = date("d/m/y"); // See if they are in the databse $query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username' AND `pass` = '$md5pass' LIMIT 1") or die(mysql_error()); if(mysql_num_rows($query) >= "1") { // Cookie is equal to 10 years setcookie("loggedin", "$username", time()+60*60*24*365*10, "/", "thecodingplace.com", 0); header("Location: index.php"); } else { echo 'Not logged in'; } } ?></td> </tr> </table></form></body></html>[/code]problem is, it sets the cookie but says not logged in, and it doesnt redirect...help? Quote Link to comment https://forums.phpfreaks.com/topic/10670-login-script/#findComment-39923 Share on other sites More sharing options...
localhost Posted May 29, 2006 Author Share Posted May 29, 2006 anyone? i really need the login and logout done. Quote Link to comment https://forums.phpfreaks.com/topic/10670-login-script/#findComment-39937 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.