Home Forums Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Arcade Chat
Go Back   ClubPenguinHQ Forums > General Discussion > Programming > PHP
Reload this Page Registration/log in script
PHP Discussion of PHP scripts belongs here.

Registration/log in script

Reply
 
LinkBack Thread Tools Display Modes
Registration/log in script
Old
  (#1)
Payton is Offline
Member
Payton is an unknown quantity at this point
 
Payton's Avatar
 
Posts: 281
Join Date: Jul 2008
Rep Power: 0
   
Default Registration/log in script - Saturday, February 21st, 2009

It's not as pointless, I guess. .__.

First, create a new MySQL database, and enter phpMyAdmin. Create a table called "users" with three tables inside it; ID, username and password.

ID: MEDIUMINT, not null, PRIMARY KEY, AUTOINCREMENT
username: VARCHAR(60)
password: VARCHAR(60)

You can create more tables if you want to. Now for the files.

register.php
Code:
<?php 
// Connects to your Database 
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); 
mysql_select_db("Database_Name") or die(mysql_error()); 

 //This code runs if the form has been submitted
if (isset($_POST['submit'])) { 

//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
        die('You did not complete all of the required fields');
    }

// checks if the username is in use
     if (!get_magic_quotes_gpc()) {
        $_POST['username'] = addslashes($_POST['username']);
    }
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") 
or die(mysql_error());
$check2 = mysql_num_rows($check);

 //if the name exists it gives an error
 if ($check2 != 0) {
        die('Sorry, the username '.$_POST['username'].' is already in use.');
                }

// this makes sure both passwords entered match
     if ($_POST['pass'] != $_POST['pass2']) {
        die('Your passwords did not match. ');
    }

    // here we encrypt the password and add slashes if needed
     $_POST['pass'] = md5($_POST['pass']);
     if (!get_magic_quotes_gpc()) {
        $_POST['pass'] = addslashes($_POST['pass']);
        $_POST['username'] = addslashes($_POST['username']);
            }

 // now we insert it into the database
     $insert = "INSERT INTO users (username, password)
              VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
     $add_member = mysql_query($insert);
     ?>

  
 <h1>Registered</h1>
 <p>Thank you, you have registered - you may now login</a>.</p>
<?php 
 } 
else 
{    
    ?>

  
   <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="10">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
</form>

 <?php
}
?>
login.php
Code:
<?php 
 // Connects to your Database 
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); 
mysql_select_db("Database_Name") or die(mysql_error()); 

  //Checks if there is a login cookie
 if(isset($_COOKIE['ID_my_site']))

  //if there is, it logs you in and directes you to the members page
{ 
    $username = $_COOKIE['ID_my_site']; 
    $pass = $_COOKIE['Key_my_site'];
         $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
     while($info = mysql_fetch_array( $check ))     
        {
         if ($pass != $info['password']) 
            {
                         }
         else
            {
            header("Location: members.php");

             }
         }
 }

  //if the login form is submitted
 if (isset($_POST['submit'])) { // if form has been submitted

  // makes sure they filled it in
     if(!$_POST['username'] | !$_POST['pass']) {
        die('You did not fill in a required field.');
    }
     // checks it against the database

     if (!get_magic_quotes_gpc()) {
        $_POST['email'] = addslashes($_POST['email']);
    }
     $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

 //Gives error if user dosen't exist
 $check2 = mysql_num_rows($check);
if ($check2 == 0) {
        die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
                }
  while($info = mysql_fetch_array( $check ))     
{
 $_POST['pass'] = stripslashes($_POST['pass']);
    $info['password'] = stripslashes($info['password']);
    $_POST['pass'] = md5($_POST['pass']);

 //gives error if the password is wrong
     if ($_POST['pass'] != $info['password']) {
        die('Incorrect password, please try again.');
    }
else 
{ 
 
// if login is ok then we add a cookie  
     $_POST['username'] = stripslashes($_POST['username']); 
      $hour = time() + 3600;  
setcookie(ID_my_site, $_POST['username'], $hour); 
setcookie(Key_my_site, $_POST['pass'], $hour);     
 
 //then redirect them to the members area 
header("Location: members.php"); 
} 
 }  
} 
 else  
{     
 
 // if they are not logged in 
?> 
 <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> 
<table border="0"> 
<tr><td colspan=2><h1>Login</h1></td></tr> 
<tr><td>Username:</td><td> 
<input type="text" name="username" maxlength="40"> 
</td></tr> 
<tr><td>Password:</td><td> 
<input type="password" name="pass" maxlength="50"> 
</td></tr> 
<tr><td colspan="2" align="right"> 
<input type="submit" name="submit" value="Login"> 
</td></tr> 
</table> 
</form> 
<?php 
} 
 
 ?>
member.php
Code:
<?php 
 // Connects to your Database  
mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); 
mysql_select_db("Database_Name") or die(mysql_error());  
 
 //checks cookies to make sure they are logged in 
if(isset($_COOKIE['ID_my_site'])) 
 {  
	$username = $_COOKIE['ID_my_site'];  
	$pass = $_COOKIE['Key_my_site']; 
	 	$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); 
 	while($info = mysql_fetch_array( $check )) 	 
		{ 
 
 //if the cookie has the wrong password, they are taken to the login page 
 		if ($pass != $info['password'])  
			{ 			header("Location: login.php"); 
			} 
 
 //otherwise they are shown the admin area	 
 	else 
			{ 
			   echo "Admin Area<p>"; 
 echo "Your Content<p>"; 
 echo "<a href=logout.php>Logout</a>"; 
   			} 
 		} 
 		} 
 else 
 
//if the cookie does not exist, they are taken to the login screen 
 {			 
header("Location: login.php"); 
} 
  ?>
And, finally, logout.php
Code:
<?php 
$past = time() - 100;  
//this makes the time in the past to destroy the cookie 
setcookie(ID_my_site, gone, $past); 
setcookie(Key_my_site, gone, $past); 
header("Location: login.php"); 
?>
You should know where to edit what, even if you have very little knowledge of PHP. Enjoy.



LARGE RED TEXT IS SUPER COOL NOW
  
Reply With Quote
Old
  (#2)
Plonk is Offline
Super Member
Plonk is an unknown quantity at this point
 
Plonk's Avatar
 
Posts: 2,458
Join Date: Apr 2008
Location: #iamthewalrus
Rep Power: 0
  Send a message via AIM to Plonk  
Default Saturday, February 21st, 2009

PHP Login Script
I'm glad you know how to copy and paste.


I have left CPHQ forever.

I will VERY occaisionally be on #iamthewalrus. Don't count on it.
  
Reply With Quote
Old
  (#3)
Billybob1234 is Offline
Super Moderator
Billybob1234 is a glorious beacon of light
 
Billybob1234's Avatar
 
Posts: 2,651
Join Date: Jan 2008
Location: Wisconsin
Age: 19
Rep Power: 25
  Send a message via AIM to Billybob1234 Send a message via MSN to Billybob1234 Send a message via Yahoo to Billybob1234 Send a message via Skype™ to Billybob1234 
Default Saturday, February 21st, 2009

Quote:
Originally Posted by Plonk View Post
PHP Login Script
I'm glad you know how to copy and paste.
Haha. I knew somebody was going to find the EXACT script he was using.


http://img196.imageshack.us/img196/769/sig2i.png
  
Reply With Quote
Old
  (#4)
Stanley is Offline
Tech God
Stanley is an unknown quantity at this point
 
Stanley's Avatar
 
Posts: 758
Join Date: Aug 2008
Rep Power: 0
  Send a message via AIM to Stanley Send a message via MSN to Stanley  
Default Saturday, February 21st, 2009

Quote:
Originally Posted by Plonk View Post
PHP Login Script
I'm glad you know how to copy and paste.
The link he got it from was Login PHP Script - Login PHP - Free Login PHP Script

And so what?
He just wanted to post it to help users.


Just an old CPHQ User.
  
Reply With Quote
Old
  (#5)
lolabob is Offline
BANNED
lolabob
 
Posts: 1,478
Join Date: Nov 2008
Location: Somewhere up above
Age: 14
Rep Power: 0
  Send a message via MSN to lolabob  
Default Saturday, February 21st, 2009

Quote:
Originally Posted by Stanley View Post
The link he got it from was Login PHP Script - Login PHP - Free Login PHP Script

And so what?
He just wanted to post it to help users.
maybe or maybe not lol:p
  
Reply With Quote
Old
  (#6)
Billybob1234 is Offline
Super Moderator
Billybob1234 is a glorious beacon of light
 
Billybob1234's Avatar
 
Posts: 2,651
Join Date: Jan 2008
Location: Wisconsin
Age: 19
Rep Power: 25
  Send a message via AIM to Billybob1234 Send a message via MSN to Billybob1234 Send a message via Yahoo to Billybob1234 Send a message via Skype™ to Billybob1234 
Default Saturday, February 21st, 2009

Quote:
Originally Posted by Stanley View Post
The link he got it from was Login PHP Script - Login PHP - Free Login PHP Script

And so what?
He just wanted to post it to help users.
I don't think he wanted to help users. I think he wanted to look smart.


http://img196.imageshack.us/img196/769/sig2i.png
  
Reply With Quote
Old
  (#7)
Adam is Offline
Forum Administrator
Adam can only hope to improve
 
Adam's Avatar
 
Posts: 4,655
Join Date: Oct 2007
Location: Ohio, USA
Age: 15
Rep Power: 0
  Send a message via AIM to Adam Send a message via MSN to Adam  
Default Saturday, February 21st, 2009

Uber owned . I kinda figured this wouldn't be yours since you said you were just learning PHP. Oh, you might wanna try PHP tags, next time, too.


SCREW DISNEY
  
Reply With Quote
Old
  (#8)
Payton is Offline
Member
Payton is an unknown quantity at this point
 
Payton's Avatar
 
Posts: 281
Join Date: Jul 2008
Rep Power: 0
   
Default Saturday, February 21st, 2009

Quote:
Originally Posted by Plonk View Post
PHP Login Script
I'm glad you know how to copy and paste.
I actually got this from Learn PHP - PHP Tutorials - PHP with MySQL Tutorials.

Edit: No, I didn't do this to look smart, I actually did it because 1.) people requested a less pointless script and this is just that, 2.) I wanted to share what I found and 3.) this is handy when you need it.

I messaged this to Matt2k5 earlier with the exact link that Stanley posted (before this thread was made), ask him.



LARGE RED TEXT IS SUPER COOL NOW

Last edited by Payton; Saturday, February 21st, 2009 at 05:50pm.
  
Reply With Quote
Reply

Lower Navigation
Go Back   ClubPenguinHQ Forums > General Discussion > Programming > PHP

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fun PHP script Payton PHP 10 Sunday, July 5th, 2009 06:47pm
****THE DISNEY SCRIPT**** Noogah General Chat 8 Thursday, January 8th, 2009 10:26pm
SCAR script? tdsq Macroing & Cheating 6 Monday, July 28th, 2008 05:43pm
Cool PCL script. Billybob1234 Macroing & Cheating 33 Thursday, July 24th, 2008 12:22am



Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
vBulletin Skin developed by: vBStyles.com
Copyright ©2006 - 2009, RancidKraut Industries