drinking_eyez Posted July 12, 2008 Share Posted July 12, 2008 I want to create a login page that should verify the username and password (from text field) with the already saved username and password in the database table. any idea? Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/ Share on other sites More sharing options...
mmarif4u Posted July 12, 2008 Share Posted July 12, 2008 Some steps to do it: 1-create a form where users will input username and password with submit button. 2-filter users inputs. 3-create a query where you will check the users input with a table in db,that is the data for that username exists or not. 4-if yes,store the username in session and redirect him to another page. 5-if not show him error with login page again. Hope this idea helps. Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588380 Share on other sites More sharing options...
JasonLewis Posted July 12, 2008 Share Posted July 12, 2008 Google it. Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588383 Share on other sites More sharing options...
talor123 Posted July 12, 2008 Share Posted July 12, 2008 i have a easy to install php script which does the following: registers accounts (user,password,email,sex,name,ip address) logs in accounts admin login to check which ip addresses have been viewing website(will soon have more features) u just gota add a few directorys and a few files... comment me if you want it Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588386 Share on other sites More sharing options...
drinking_eyez Posted July 12, 2008 Author Share Posted July 12, 2008 Some steps to do it: 1-create a form where users will input username and password with submit button. 2-filter users inputs. 3-create a query where you will check the users input with a table in db,that is the data for that username exists or not. 4-if yes,store the username in session and redirect him to another page. 5-if not show him error with login page again. Hope this idea helps. i made user input form. dont know how to do 2 and 3 step... can you please explain what you mean by filter user input, and provide a query sample aswell if possible (for step 3) Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588407 Share on other sites More sharing options...
mmarif4u Posted July 12, 2008 Share Posted July 12, 2008 ok. Form: <form action='' method='post'> <input type='text' name ='username'><br> <input type='password' name='password'><br> <input type='submit' name='submit' value='login'> </form> Now: <?php $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string($_POST['password']); if(isset($_POST['submit'])){ if($username == ''){ echo "Please fill in username field"; } elseif($password == ''){ echo "Please fill in password field"; }else{ $sql="select username from table where username='$username' and password='$password'"; $q=mysql_query($sql); $num=mysql_num_rows($q); if($num < 0){ echo "NO match found"; }else { $_SESSION['username']=$username; header('location:index.php'); } } } ?> Make sure you are connected to mysql. Hope this will helps. Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588422 Share on other sites More sharing options...
JasonLewis Posted July 12, 2008 Share Posted July 12, 2008 Okay.. Here is a link to a tutorial that you might find helpful: http://gigaspartan.com/?p=6 http://www.combined-minds.net/tutorials/28/Creating_a_user_login_and_registration_system.http://www.gfx-depot.com/forum/-tutorial-index-t-1033.html Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588423 Share on other sites More sharing options...
mmarif4u Posted July 12, 2008 Share Posted July 12, 2008 Was missing session start. Updated: name it as test.php <?php session_start(); $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string($_POST['password']); if(isset($_POST['submit'])){ if($username == ''){ echo "Please fill in username field"; } elseif($password == ''){ echo "Please fill in password field"; }else{ $sql="select username from table where username='$username' and password='$password'"; $q=mysql_query($sql); $num=mysql_num_rows($q); if($num < 0){ echo "NO match found"; }else { $_SESSION['username']=$username; header('location:index.php'); } } } ?> You can make index.php. <?php session_start(); $username=$_SESSION['username']; if($username != ''){ echo "Hi,you are logged in successfully."; } else { header('location:test.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588433 Share on other sites More sharing options...
drinking_eyez Posted July 12, 2008 Author Share Posted July 12, 2008 <?php $hostname = "localhost"; $db_user = "root"; $db_password = "mother"; $db_table = "new_login"; //$created_on = date("U",$timestamp); $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db("rdms",$db); ?> <html > <head> </head> <link rel="stylesheet" type="text/css" media="screen" href="abc.css" /> <body> <fieldset> <legend> Login </legend> <img src="header.jpg" align="top"> <? session_start(); $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string($_POST['password']); if(isset($_POST['submit'])){ if($username == ''){ echo "Please fill in username field"; } elseif($password == ''){ echo "Please fill in password field"; }else{ $sql="select username from table where username='$username' and password='$password'"; $q=mysql_query($sql); $num=mysql_num_rows($q); if($num < 0){ echo "NO match found"; }else { $_SESSION['username']=$username; header('location:index1.php'); } } } ?> <form method="post" action=""> <table width="470"> <tbody> <tr> <td>User Name:</td> <td><input type="text" name="$username" class="abc"></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="$password" class="abc"></td> </tr> </tbody></table> </fieldset> <br><br> <input type="submit" name="Submit" value="Submit"> </form> </html> index1.php <?php session_start(); $username=$_SESSION['username']; if($username != ''){ echo "Hi,you are logged in successfully."; } else { header('location:login1.php'); } ?> here is my piece of code but its not doing anything... can you make appropriate changes for that if login successful, it redirect to another page? (say main.php) Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588510 Share on other sites More sharing options...
drinking_eyez Posted July 12, 2008 Author Share Posted July 12, 2008 help plzzzz Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588529 Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 http://gigaspartan.com/?p=6 http://www.combined-minds.net/tutorials/28/Creating_a_user_login_and_registration_system.http://www.gfx-depot.com/forum/-tutorial-index-t-1033.html They should be more then enough help. Quote Link to comment https://forums.phpfreaks.com/topic/114419-login-page-creation-help/#findComment-588691 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.