|
|
|
|
![]() ![]() |
Aug 22 2007, 11:57 AM
Post
#1
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 7 Joined: 22-August 07 Member No.: 24,272 |
Hi guys, ive got a registration system that looks something like the one below:
CODE <html> <body><form action="insert.php" method="post"> Firstname: <input type="text" name="username" /> Lastname: <input type="text" name="password" /> <input type="submit" /> </form></body> </html> Then i have inset.php, which looks like the following: CODE <?php $con = mysql_connect("localhost","autobot","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con);$sql="INSERT INTO person (username, password) VALUES ('$_POST[username]','$_POST[password]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added";mysql_close($con) ?> Now my question is, how do i create a login system using PHP and MYSQL, because im missing something obvios here i think. ~Thank you |
|
|
|
Aug 22 2007, 12:17 PM
Post
#2
|
|
|
Advanced Member Group: Members Posts: 170 Joined: 30-July 07 Member No.: 23,704 |
Actually looking at your Form, its quite weird. Having Firstname as username and Lastname as password. But anyway, just take assume that you want it to be like this. So the question is you want to allow the user to login after registration?? Below will be an example of a login script.
Here is a minor modification to your registration form. This will be something like login.php for the user to enter their data. CODE <html> <body><form action="access.php" method="post"> Username: <input type="text" name="username" /> Password: <input type="text" name="password" /> <input type="submit" /> </form></body> </html> So after Submit button is click, it will be send to access.php. The codes below will be used to verify the user. CODE <?php session_start(); $con = mysql_connect("localhost","autobot","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $sql="SELECT * FROM person where username = '$_POST[username]' and password = '$_POST[password]'"; $result = mysql_query($sql); if ($result == 0) { die('Error: ' . mysql_error()); } echo "Login Success"; $_SESSION[‘user’] = $result; mysql_close($con) ?> The above is just an example of login. You can use that session on every page by calling $_SESSION[‘user’]. There's a lot better ones out there and of course you can use those for free. If you want more security, you can use hashing or security id for accessing pages. Hope this help a bit. Cheers |
|
|
|
Aug 23 2007, 09:02 AM
Post
#3
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 7 Joined: 22-August 07 Member No.: 24,272 |
Alright, i got a login and registration system working, the last thing i need is how to show differant users differant things, lets say i want the admin to see "Welcome Admin" and i want a member to see "Login successful" how would i do that?
(sorry if im annoying you guys now |
|
|
|
May 14 2008, 05:14 PM
Post
#4
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 14-May 08 From: uk gb Member No.: 30,333 |
login code ect.this is a really good code worked great for me. it has reg page, login page ect. really good just put where your ftp is and open index.html and follow on from there
|
|
|
|
Jul 2 2008, 09:34 PM
Post
#5
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 10 Joined: 2-July 08 Member No.: 31,263 |
This is the login main page for the one i use.
CODE if($session->logged_in){ echo "<h1>Logged In</h1>"; echo "Welcome <b>$session->username</b>, you are logged in. <br><br>" ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] " ."[<a href=\"useredit.php\">Edit Account</a>] " ."[<a href=\"../upload/upload.php\">File Upload</a>] " ."[<a href=\"../egbtdata.php?start=0&end=50&order=playerID\">EGBT Database</a>] "; if($session->isAdmin()){ echo "[<a href=\"admin/admin.php\">Admin Center</a>] "; } echo "[<a href=\"process.php\">Logout</a>]"; } else{ ?> <h1>Login</h1> <? /** * User not logged in, display the login form. * If user has already tried to login, but errors were * found, display the total number of errors. * If errors occurred, they will be displayed. */ if($form->num_errors > 0){ echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>"; } ?> <form action="/includes/process.php" method="POST"> <table align="left" border="0" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr> <tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>> <font size="2">Remember me next time <input type="hidden" name="sublogin" value="1"> <input type="submit" value="Login"></td></tr> <tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr> <tr><td colspan="2" align="left"><!--<br>Not registered? <a href="register.php">Sign-Up!</a>--></td></tr> </table> </form> |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 4th July 2008 - 04:22 PM |