IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Php/mysql Login/register

, Tutorial for login with databases.

kiro
no avatar
Newbie [Level 1]
*
Group: Members
Posts: 13
Joined: 31-March 05
Member No.: 5,051



Post #1 post Mar 31 2005, 01:03 AM
Start register code. Register.php
CODE

<form method=post action=register.php?action=register  name=s>
<table>
<tr><td>Username:</td><td><input type=text name=user></td></tr>
<tr><td>Email:</td><td><input type=text name=email></td></tr>
<tr><td>Pass:</td><td><input type=password name=pass></td></tr>
<tr><td>Verify Pass:</td><td><input type=password name=vpass></td></tr>
<tr><td colspan=2 align=center><input type=submit value=Register></td></tr>
</table>
</form>
<?php

//Login to your database. Make the fields of course..
mysql_connect("localhost","user","pass");
mysql_select_db("database");
//end

//if registering, check fields.
if ($action == register) {

if (!$user || !$pass || !$email || !$vpass) {
 print "You must fill out all fields.";

 exit;
}
$dupe1 = mysql_num_rows(mysql_query("select * from table where user='$user'"));

if ($dupe1 > 0) {
 print "Someone already has that username.";

 exit;
}
$dupe2 = mysql_num_rows(mysql_query("select * from table where email='$email'"));
if ($dupe2 > 0) {
 print "Someone already has that email.";

 exit;
}

//check if passwords are the same
if ($pass != $vpass) {
 print "The passwords do not match.";

 exit;
}
//end
//insert
mysql_query("insert into table (user, email, pass) values('$user','$email','$pass')");
print "You are now registered. Login.";
}
?>



Now that you are done with register, make the login. Login.php
CODE

<form method=post action=Login.php?action=login>
<table>
<tr><td>Email:</td><td><input type=text name=email></td></tr>
<tr><td>Pass:</td><td><input type=password name=pass></td></tr>
<tr><td colspan=2 align=center><input type=submit value=Login></td></tr>
</form>
</table>
<?php
if($action==login){
//check
if (!$email || !$pass) {
print "Please fill out all fields.";

exit;
}
$logres = mysql_num_rows(mysql_query("select * from table where user='$email' and pass='$pass'"));
if ($logres <= 0) {
print "Login failed. If you have not already, please signup. Otherwise, check your spelling and login again.";

exit;
} else {
//logged in, register the session..
session_register("email");
session_register("pass");
print "You are now logged in..";
}
}
?>


Now, this is members.php, it checks if the session is registered or not..

CODE

<?php
if (!session_is_registered("email") || !session_is_registered("pass")) {
print "You need to login to view this page!! ";
exit;
}
print "Content here";
?>



Ok, we are done, if you do not know how to do the mysql for the pages, here is the sql code:

CODE

CREATE TABLE `table` (
 `id` int(5) NOT NULL auto_increment,
 `user` varchar(255) NOT NULL default '',
 `email` varchar(255) NOT NULL default '',
 `pass` varchar(255) NOT NULL default '',
 PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1;



Thats it! smile.gif
Go to the top of the page
+Quote Post
rambo406
no avatar
Newbie [Level 1]
*
Group: Members
Posts: 13
Joined: 1-April 05
Member No.: 5,152



Post #2 post Apr 2 2005, 08:30 AM
O.O are u sure that's all?
Go to the top of the page
+Quote Post
maddog39
no avatar
Super Member
*********
Group: Members
Posts: 208
Joined: 27-January 05
From: LI, New York
Member No.: 3,448



Post #3 post Apr 2 2005, 07:19 PM
Yeah there could be an admin center to delete members and/or an IP banning tool. biggrin.gif
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts 3 chalawanonline 361 2nd August 2004 - 02:34 PM
Last post by: Spectre
No New Posts   1 bowjthewen 285 4th August 2004 - 05:27 AM
Last post by: OpaQue
No New Posts   2 zachtk8702 499 13th August 2004 - 04:26 PM
Last post by: zachtk8702
No New Posts   7 Raptrex 432 27th August 2004 - 11:16 PM
Last post by: Spectre
No New Posts 4 NuHoaXuLa 411 29th August 2004 - 03:12 AM
Last post by: NuHoaXuLa
No New Posts   11 Triple X 720 5th September 2004 - 02:33 AM
Last post by: Triple X
No New Posts   4 Schweden 285 8th September 2004 - 09:40 AM
Last post by: Schweden
No New Posts   2 Too_Hot 305 16th September 2004 - 05:25 PM
Last post by: serverph
No New Posts   2 BoSZ 405 17th September 2004 - 09:09 PM
Last post by: BoSZ
No New Posts   6 XtremeGamer99 268 10th October 2004 - 07:54 PM
Last post by: moscower
No New Posts   1 pollux1er 737 24th July 2007 - 11:13 PM
Last post by: matak
No New Posts   8 guangdian 294 2nd October 2004 - 05:03 AM
Last post by: football123213
No New Posts   3 JaVe 297 2nd October 2004 - 04:14 PM
Last post by: JaVe
No New Posts   3 outwarsecrets 616 10th October 2004 - 08:04 AM
Last post by: whatknows
No New Posts   0 farsiscript 442 10th June 2006 - 07:01 PM
Last post by: farsiscript


 



RSS Lo-Fi Version Time is now: 5th December 2008 - 07:51 AM