Jump to content
xisto Community
FaLgoR

Complete Login System With PHP + MYSQL

Recommended Posts

Thanks! I was searching for such a script in hotscripts.com for a long time! Maybe you could even submit the script...

214798[/snapback]


Yeah - thanks very very very much - This is well needed, and will go to great use on the next version of my website - thanks! ;)

Share this post


Link to post
Share on other sites

hmm klind of strange to miss out conn.php its like a vital part of the login system. I am wondering whether this person actually coded it him self or stole it from some one else cos if he coded it him self he woluld not have left out conn.php. Just a thought thats all.Yeah good script for beginners could have doen without the errors cos I got conn.php errors too ;). good base for a login script thou, at least now I wont forget any of the code requiired...

Share this post


Link to post
Share on other sites

I think I know why it's missing conn.php and that it doesn't work. Perhaps a copied article? Even if it is wrapped in quotes, please avoid using other people's articles. Thanks

Share this post


Link to post
Share on other sites

Huh i dont know... Do i need to insert some table in db ?? Where will be stored accounts i know i need to have user name for db, and to have database but i need to have in database and table for accounts to store it??

Share this post


Link to post
Share on other sites

You see this is why programming newbs should not copy articles cos information is misleading...And by the looks of it this script requires only one talbe...the collums would benameageloginemailpasswordpassword2I would not be sure about the setting of these collums as I would need to test the script which I dunno if I really want to cos this script looks very...well...whatg more can I say if conn.php was missed outsorry to reply to my own post but I forgot to add:ernad this table will be put within a db which will store your users accounts...it is better if you just go to hotscripts.com and search for a login script cos im not too sure if this tutorial should have been accepted...

Notice from jlhaslip:
merged two posts

Share this post


Link to post
Share on other sites

here is sql:

CREATE TABLE `members` (  `name` varchar(60) character set utf8 default NULL,
  `email` varchar(255) character set utf8 NOT NULL,
  `age` varchar(3) character set utf8 default NULL,
  `login` varchar(50) character set utf8 NOT NULL,
  `password` varchar(40) character set utf8 NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;


and i`m edited page:

register:

<?include("conn.php"); // create a file with all the database connections

if($do_register){ // if the submit button were clicked
if((!$name) || (!$email) || (!$age) || (!$login) || (!$password) || (!$password2)){
print "You can't let any fields in blank.\n"; // if the user did not put some field
exit;
}
$name = stripslashes($name);
$email = stripslashes($email);
$age = stripslashes($age);
$login = stripslashes($login);
$password = stripslashes($password);
$password2 = stripslashes($password2);

// this is for security reasons

if($password != $password2){ // if passwords didn't match
print "The password and the confirmation are not the same!\n";
exit;
}
$password = md5($password);
mysql_query("INSERT INTO members (name,email,age,login,password) VALUES ('$name','$email',$age,'$login','$password')") or die (mysql_error());
header("Location: login.php");
exit;
} // close the first "if"
?>
<form action="register.php" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
Age: <input type="text" name="age"><br>
Login: <input type="text" name="login"><br>
Password: <input type="password" name="password"><br>
Password Again: <input type="password" name="password2"><br>
<input type="submit" name="do_register" value="Sumbit">
</form>

login.php:

<?include("conn.php");

if($do_login){
$login = stripslashes($login); // VERY IMPORTANT FOR SECURITY OF YOUR DATABASE DON'T ERASE IT
$passwd = stripslashes($passwd); // VERY IMPORTANT FOR SECURITY OF YOUR DATABASE DON'T ERASE IT

$check = mysql_query("SELECT * FROM members WHERE login='$login' LIMIT 1;");
$user = mysql_fetch_array($check);

if($user[password] == md5($passwd)){ // if the writed password and the db password are the same...

setcookie("login","$login",time()+360000);
setcookie("pass","$passwd",time()+360000);
// ...set the cookies...
header("Location: userspage.php"); // ...and redirect to restrict page
}else{
print "Login or password incorrects!\n";
exit;
}
}
?>

<form action="login.php" method="post">
Login: <input type="text" name="login"><br>
Passwd: <input type="password" name="passwd">
<input type="submit" name="do_login" value="Log-in!">
</form>

verify.php :

<?include("conn.php"); // include page with the database connection
$cookie = $HTTP_COOKIE_VARS; // to reduce the var's name :))

if($cookie[login] && $cookie[pass]){

$login = $cookie[login];
$pass = $cookie[pass];

$usrquery = mysql_query("SELECT * FROM members WHERE nick='$login' AND password='$pass';") or die (mysql_error()); // search for the user
$user = mysql_fetch_array($usrquery);

if($user[level] != 'Admin')
header("Location: notfound.htm"); // if the user is not an admin, redirect to an error page
}
?>

Now will work

Share this post


Link to post
Share on other sites

i can never get codes like these to work >_< it kinda sucks, it keeps teling me-

$host = 'localhost'; $user = 'albus_chris'; $pass = 'dontuwish'; $db = 'albus_login'; mysql_connect($host,$user,$pass) or die ("Database is unavaiable. Please try again later."); mysql_select_db($db) or die ("Database is unavaiable. Please try again later.");

at the top of evey page..ne clue whats going on? the conn.php file should look exactly like this right?

$host = 'localhost';$user = 'albus_albus';$pass = 'PWHERE;$db = 'albus_login';mysql_connect($host,$user,$pass) or die ("Database is unavaiable. Please try again later.");mysql_select_db($db) or die ("Database is unavaiable. Please try again later.");


or is it supposed to look different? i copied it from the origional post here and it didn't work..

please help! maybe i have the code wrong, i hope that is the problem >_<

Share this post


Link to post
Share on other sites

I edited this scripts after ernads post.. here is what problems now I have:admin.phpprofiles.phpverify.phpwhen open these page sit shows Unknown column 'nick' in 'where clause' and when user fills register form it is redirected to login page.. but when it trys to login it always says incorrecty login or password..what should I do? :)

Share this post


Link to post
Share on other sites

merci bouceup :)

Notice from jlhaslip:
Added some garlic, but this is still SPAM, and you have previously been warned about short, one line answers being unacceptable. Read the Xisto readme file and remind yourself what these Forums require for Content.Warn issued.Bonjour.
Edited by jlhaslip (see edit history)

Share this post


Link to post
Share on other sites

I think it's better to use PHP SESSION than COOKIE. coz some user may disabled it. something like this:

if ($do_login) {$query = mysql_query("SELECT * FROM members WHERE login='$login' AND password='$password');if (mysql_num_rows($query) > 0) { $_SESSION['logged'] = $login; // some code here} else { print 'Username or password did not match'; exit;}}

So, in every members page we can use:

if (!isset($_SESSION['logged']) {  // if not logged in} else {  // member page goes here}

Just an advice! <_<
Edited by masterio (see edit history)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.