Anders Moen Posted January 14, 2007 Share Posted January 14, 2007 Anyone got a PHP and MySQL login script? I want people to log on their account, and when they're logged in, they can for example edit personal information and stuff like that...if anyone got one, can you give it to me or something?I have one now, but it doesn't use cookies so it doesn't remember the user name so only at first when you've logged in, it says "Welcome user_name!" and if I then come back later, it only say Welcome !So...if anyone got one, I'd really like to have it (I have a MySQL db). Link to comment Share on other sites More sharing options...
Kristian_C Posted January 14, 2007 Share Posted January 14, 2007 <?if($_POST['login'] && $_POST['username'] && $_POST['password']){$username=$_POST['username'];$password=$_POST['password'];$check=mysql_query("SELECT * FROM users WHERE username='$username'");$checkuser=mysql_num_rows($check);$checkpass=mysql_fetch_object($check);if($checkuser == 0){echo"That user is not in our db.";exit();}if($checkpass->password != $password){echo"Wrong password";exit();}else{session_register('username'); header("Location: home.php");}} buttons and other things i supose you can create yourself.Dident test it but think it should do it..if not, tell me and ill try it and fix errors...->Kristian_C. Link to comment Share on other sites More sharing options...
Anders Moen Posted January 14, 2007 Author Share Posted January 14, 2007 Not exactly what I was looking for Kristian.I meant to log in by typing in username and password, and the usernames and passwords should be in a database... Link to comment Share on other sites More sharing options...
Kristian_C Posted January 14, 2007 Share Posted January 14, 2007 Not exactly what I was looking for Kristian.I meant to log in by typing in username and password, and the usernames and passwords should be in a database...Hmm, i just wrote the code you can use, i just hate writing html you will need to create a register script tho...but login script is there.->Kristian_C. Link to comment Share on other sites More sharing options...
Anders Moen Posted January 14, 2007 Author Share Posted January 14, 2007 Yea, I have a register script (and a login script), but I them to be able to have a personal site, like you can at this forum. And I cannot do that with the one I have now... Link to comment Share on other sites More sharing options...
Kristian_C Posted January 14, 2007 Share Posted January 14, 2007 Yea, I have a register script (and a login script), but I them to be able to have a personal site, like you can at this forum. And I cannot do that with the one I have now...use :session_start();$username=$_SESSION['username'];on top of every page, then have a link to a php page like functions.php and have this code there :<?function erhanlogin(){if (empty($_SESSION['username'])){echo "<script LANGUAGE='JavaScript'>window.location='index.php';</script>";exit();}}erhanlogin();?>only include on the files where you need to be logged in tho.->Kristian_C. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now