Similar topics
Latest topics
Club Penguin Events
Advertisement
Login and Register Script Codes
2 posters
Page 1 of 1
Login and Register Script Codes
1)Stuff you must have to make a login and register page.
> XAMPP for Mac or WAMP for Windows
> A text editor (I recommend Notepad++)
> The latest PHP version
2)Open up your web server's control panel and activate Apache and MySQL. Leave the window open.
3)Open up a web browser and type [You must be registered and logged in to see this link.] And change your Phpmyadmin password to whatever you like.
4)Create a new database. Name it : Test . Next, go to your database and create a new table. Name that table : users and put 3 in the number of rows.
5)In the first field, type id. Type 10 in the Length/Values. The type must be MEDIUMINT. Click on Index drop down list and select PRIMARY. Click check on AUTO_INCREMENT.
6)Next, type username in the second field. Type 15 in the Length/Values. The type must be VARCHAR.
7)On the last field, type password. Type 15 in the Length/Values. The type must be VARCHAR. Click save. Leave the window open.
8)Open up your notepad. Copy and paste the whole Register code into it.
Register code:
9)Save it as register.php and change the option to all files in C:/YourWebServerHere/htdocs. Change the 'YourWebServerHere' to the server you used for example: C:/xampp/htdocs.
10)Open a new Notepad page and copy and paste this whole code:
11)Change the db_username, db_password and db_name to your own username, password and database name.
12)Save it as all files and name it registernext.php in the htdocs folder.
13)To test it out, go to [You must be registered and logged in to see this link.] . If it works, it will say 'Success!'. If it doesn't re-read the whole tut again.
14)Next, open up another page in your notepad and copy and paste the code below. Save it as login.php in htdocs.
15)Change the db_username, db_password, db_name into your own.
16)Next, open another notepad page and type the following code. Save it as all files and change the name to loginsuccess.php .
17)Lastly, for the logout code, copy and paste this code in your new notepad page. Save it as all files and change name to logout.php . Save it to htdocs.
18)To test it out, go to [You must be registered and logged in to see this link.] and to login, go to [You must be registered and logged in to see this link.]
Please comment if I made any errors whatsoever.
In the next tutorial, I'll be showing the basics of PHP.
> XAMPP for Mac or WAMP for Windows
> A text editor (I recommend Notepad++)
> The latest PHP version
2)Open up your web server's control panel and activate Apache and MySQL. Leave the window open.
3)Open up a web browser and type [You must be registered and logged in to see this link.] And change your Phpmyadmin password to whatever you like.
4)Create a new database. Name it : Test . Next, go to your database and create a new table. Name that table : users and put 3 in the number of rows.
5)In the first field, type id. Type 10 in the Length/Values. The type must be MEDIUMINT. Click on Index drop down list and select PRIMARY. Click check on AUTO_INCREMENT.
6)Next, type username in the second field. Type 15 in the Length/Values. The type must be VARCHAR.
7)On the last field, type password. Type 15 in the Length/Values. The type must be VARCHAR. Click save. Leave the window open.
8)Open up your notepad. Copy and paste the whole Register code into it.
Register code:
- Code:
<form action="registernext.php" 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>
9)Save it as register.php and change the option to all files in C:/YourWebServerHere/htdocs. Change the 'YourWebServerHere' to the server you used for example: C:/xampp/htdocs.
10)Open a new Notepad page and copy and paste this whole code:
- Code:
<?php
// Connects to your Database
mysql_connect("localhost", "db_username", "db_password") or die(mysql_error());
mysql_select_db("db_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. [<a href = "http://www.camppenguinworld.com/?page_id=7">Back]');
}
// 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. [<a href = "http://www.camppenguinworld.com/?page_id=7">Back]');
}
// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. [<a href = "http://www.camppenguinworld.com/?page_id=7">Back] ');
}
// 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);
}
?>
<html>Success!</html>
11)Change the db_username, db_password and db_name to your own username, password and database name.
12)Save it as all files and name it registernext.php in the htdocs folder.
13)To test it out, go to [You must be registered and logged in to see this link.] . If it works, it will say 'Success!'. If it doesn't re-read the whole tut again.
14)Next, open up another page in your notepad and copy and paste the code below. Save it as login.php in htdocs.
- Code:
<?php
// Connects to your Database
mysql_connect("localhost", "db_username", "db_password") or die(mysql_error());
mysql_select_db("db_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: index.html");
}
}
}
//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: loginsuccess.php");
}
}
}
else
{
// if they are not logged in
?>
<form action="loginsuccess.php" 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
}
?>
15)Change the db_username, db_password, db_name into your own.
16)Next, open another notepad page and type the following code. Save it as all files and change the name to loginsuccess.php .
- Code:
<?php
// Connects to your Database
mysql_connect("localhost", "db_username", "db_password") or die(mysql_error());
mysql_select_db("db_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");
}
?>
<h1> Login successfully! </h1>
17)Lastly, for the logout code, copy and paste this code in your new notepad page. Save it as all files and change name to logout.php . Save it to htdocs.
- 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");
?>
18)To test it out, go to [You must be registered and logged in to see this link.] and to login, go to [You must be registered and logged in to see this link.]
Please comment if I made any errors whatsoever.
In the next tutorial, I'll be showing the basics of PHP.
Rarreninja- Posts : 3
Reputation : 0
Join date : 2010-11-02
Age : 27
Location : In your Closet. :3
Similar topics
» (This is not my script) i just made the formation (Bot Army)
» Ozzy's Bot Script
» Hello World Script
» Ozzy's Bot Script
» Hello World Script
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Feb 05, 2019 5:36 am by Gizmo92883
» Anybody else come to this forum for the memories?
Tue Jun 12, 2018 12:07 am by Cooldude21
» This forum died
Thu Mar 30, 2017 11:10 pm by _Skate_
» Introduce yourselves!
Fri Jan 23, 2015 7:21 pm by Gizmo92883
» Ozzy's Bot Script
Mon May 13, 2013 8:31 am by Pig
» Goodbye BCPB Forums.
Tue Sep 18, 2012 6:37 pm by 43nînjâ17
» Follow bot script (100% Credit to Cp-Cheater )
Sun Sep 16, 2012 4:55 pm by Dentonbrooks
» Xat Main Owner Hacker
Fri Aug 17, 2012 2:32 am by 43nînjâ17
» xat message big
Sat Aug 11, 2012 12:32 am by 43nînjâ17