Home > Uncategorized > Script PHP login v1.0

Script PHP login v1.0

Sekarang banyak sekali kegunaan PHP, nah ane punya Ilmu sedikit untuk di Share semoga bermanfaat

activete.php

<?php
session_start();
include (‘dbc.php’);

if (!isset($_GET[‘usr’]) && !isset($_GET[‘code’]) )
{
$msg = “ERROR: Invalid code…”;
exit();
}

$rsCode = mysql_query(“SELECT activation_code from users where user_email=’$_GET[usr]'”) or die(mysql_error());

list($acode) = mysql_fetch_array($rsCode);

if ($_GET[‘code’] == $acode)
{
mysql_query(“update users set user_activated=1 where user_email=’$_GET[usr]'”) or die(mysql_error());
echo “<h3>Thank you </h3>Email confirmed and account activated. You can <a href=\”login.php\”>login</a> now..”;
} else
{ echo “ERROR: Incorrect activation code…not valid”; }
?>

Untuk connection pake

<?php
$dbname = ‘phplogin’;
$link = mysql_connect(“localhost”,”root”,””) or die(“Couldn’t make connection.”);
$db = mysql_select_db($dbname, $link) or die(“Couldn’t select database”);
?>

login.php

<?php
include ‘dbc.php’;

$user_email = mysql_real_escape_string($_POST[’email’]);

if ($_POST[‘Submit’]==’Login’)
{
$md5pass = md5($_POST[‘pwd’]);
$sql = “SELECT id,user_email FROM users WHERE
user_email = ‘$user_email’ AND
user_pwd = ‘$md5pass’ AND user_activated=’1′”;

$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);

if ( $num != 0 ) {

// A matching row was found – the user is authenticated.
session_start();
list($user_id,$user_email) = mysql_fetch_row($result);
// this sets variables in the session
$_SESSION[‘user’]= $user_email;

if (isset($_GET[‘ret’]) && !empty($_GET[‘ret’]))
{
header(“Location: $_GET[ret]”);
} else
{
header(“Location: myaccount.php”);
}
//echo “Logged in…”;
exit();
}

header(“Location: login.php?msg=Invalid Login”);
//echo “Error:”;
exit();
}

?>

<link href=”styles.css” rel=”stylesheet” type=”text/css”>

<?php if (isset($_GET[‘msg’])) { echo “<div class=\”msg\”> $_GET[msg] </div>”; } ?>

<p>&nbsp;</p><table width=”40%” border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
<tr>
<td bgcolor=”#d5e8f9″ >
<div align=”center”><font size=”5″><strong>Login
Members</strong></font></div></td>
</tr>
<tr>
<td bgcolor=”#e5ecf9″><form name=”form1″ method=”post” action=””>
<p>&nbsp;</p>
<p align=”center”>Your Email
<input name=”email” type=”text” id=”email”>
</p>
<p align=”center”> Password:
<input name=”pwd” type=”password” id=”pwd”>
</p>
<p align=”center”>
<input type=”submit” name=”Submit” value=”Login”>
</p>
<p align=”center”><a href=”register.php”>Register</a> | <a href=”forgot.php”>Forgot</a></p>
</form></td>
</tr>
</table>

forgot.php

<?php
include ‘dbc.php’;
if ($_POST[‘Submit’]==’Send’)
{
$host = $_SERVER[‘HTTP_HOST’];
$rs_search = mysql_query(“select user_email from users where user_email=’$_POST[email]'”);
$user_count = mysql_num_rows($rs_search);

if ($user_count != 0)
{
$newpwd = rand(1000,9999);
$host = $_SERVER[‘HTTP_HOST’];
$newmd5pwd = md5($newpwd);
mysql_query(“UPDATE users set user_pwd=’$newmd5pwd’ where user_email=’$_POST[email]'”);
$message =
“You have requested new login details from $host. Here are the login details…\n\n
User Name: $_POST[email] \n
Password: $newpwd \n
____________________________________________
*** LOGIN ***** \n
To Login: http://$host/login.php \n\n
_____________________________________________
Thank you. This is an automated response. PLEASE DO NOT REPLY.
“;

mail($_POST[’email’], “New Login Details”, $message,
“From: \”Auto-Response\” <robot@$host>\r\n” .
“X-Mailer: PHP/” . phpversion());

die(“Thank you. New Login details has been sent to your email address”);
} else die(“Account with given email does not exist”);

}
?>
<h3>Forgot Password</h3>
<p>Please enter your email address and the new password will be sent.</p>
<table width=”50%” border=”0″ cellpadding=”1″ cellspacing=”0″>
<tr>
<td>
<form name=”form1″ method=”post” action=””>
<p><br>
<strong>Email:</strong>
<input name=”email” type=”text” id=”email”>
<input type=”submit” name=”Submit” value=”Send”>
</p>
</form></td>
</tr>
</table>
<p>&nbsp;</p>

logout.php

<?php
session_start();
unset($_SESSION[‘user’]);
header(“Location: login.php”);
?>

myaccount.php

<?php
session_start();
if (!isset($_SESSION[‘user’]))
{
die (“Access Denied”);
}
?>
<h2>My Account </h2>
<?php if (isset($_SESSION[‘user’])) { ?>
<p>Logged as <?php echo $_SESSION[‘user’]; ?> | <a href=”settings.php”>Settings</a>
| <a href=”logout.php”>Logout</a> </p>
<?php } ?>

Nah saya karena pake gambar saya sertakan

pngimg.php

<?php
session_start();
header (“Content-type: image/png”);

$rno = rand(1000,99999);
$_SESSION[‘ckey’] = md5($rno);

$img_handle = imageCreateFromPNG(“bg1.PNG”);
$color = ImageColorAllocate ($img_handle, 0, 0, 0);
ImageString ($img_handle, 5, 20, 13, $rno, $color);
ImagePng ($img_handle);
ImageDestroy ($img_handle);

?>

kalau tidak ingin ya tidak usah pakai tidak wajib sih,,hehehe

register.php

<?php
session_start();

include (‘dbc.php’);

if ($_POST[‘Submit’] == ‘Register’)
{
if (strlen($_POST[’email’]) < 5)
{
die (“Incorrect email. Please enter valid email address..”);
}
if (strcmp($_POST[‘pass1’],$_POST[‘pass2’]) || empty($_POST[‘pass1’]) )
{
//die (“Password does not match”);
die(“ERROR: Password does not match or empty..”);

}
if (strcmp(md5($_POST[‘user_code’]),$_SESSION[‘ckey’]))
{
die(“Invalid code entered. Please enter the correct code as shown in the Image”);
}
$rs_duplicates = mysql_query(“select id from users where user_email=’$_POST[email]'”);
$duplicates = mysql_num_rows($rs_duplicates);

if ($duplicates > 0)
{
//die (“ERROR: User account already exists.”);
header(“Location: register.php?msg=ERROR: User account already exists..”);
exit();
}

$md5pass = md5($_POST[‘pass2’]);
$activ_code = rand(1000,9999);
$server = $_SERVER[‘HTTP_HOST’];
$host = ereg_replace(‘www.’,”,$server);
mysql_query(“INSERT INTO users
(`user_email`,`user_pwd`,`country`,`joined`,`activation_code`,`full_name`)
VALUES
(‘$_POST[email]’,’$md5pass’,’$_POST[country]’,now(),’$activ_code’,’$_POST[full_name]’)”) or die(mysql_error());

$message =
“Thank you for registering an account with $server. Here are the login details…\n\n
User Email: $_POST[email] \n
Password: $_POST[pass2] \n
Activation Code: $activ_code \n
____________________________________________
*** ACTIVATION LINK ***** \n
Activation Link: http://$server/activate.php?usr=$_POST%5Bemail%5D&code=$activ_code \n\n
_____________________________________________
Thank you. This is an automated response. PLEASE DO NOT REPLY.
“;

mail($_POST[’email’] , “Login Activation”, $message,
“From: \”Auto-Response\” <notifications@$host>\r\n” .
“X-Mailer: PHP/” . phpversion());
unset($_SESSION[‘ckey’]);
echo(“Registration Successful! An activation code has been sent to your email address with an activation link…”);

exit;
}

?>
<link href=”styles.css” rel=”stylesheet” type=”text/css”>
<?php if (isset($_GET[‘msg’])) { echo “<div class=\”msg\”> $_GET[msg] </div>”; } ?>
<p>&nbsp;</p>
<table width=”65%” border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td bgcolor=”d5e8f9″><strong><font size=”5″>Register Account</font></strong></td>
</tr>
<tr>
<td bgcolor=”e5ecf9″><form name=”form1″ method=”post” action=”register.php” style=”padding:5px;”>
<p><br>
Name:
<input name=”full_name” type=”text” id=”full_name”>
Ex. John Wilson</p>
<p>Email:
<input name=”email” type=”text” id=”email”>
Ex. john@domain.com</p>
<p>Password:
<input name=”pass1″ type=”password” id=”pass1″>
Atleast 5 chars</p>
<p>Retype Password:
<input name=”pass2″ type=”password” id=”pass2″>
</p>
<p>Country:
<select name=”country” id=”select8″>
<option value=”Afghanistan”>Afghanistan</option>
<option value=”Albania”>Albania</option>
<option value=”Algeria”>Algeria</option>
<option value=”Andorra”>Andorra</option>
<option value=”Anguila”>Anguila</option>
<option value=”Antarctica”>Antarctica</option>
<option value=”Antigua and Barbuda”>Antigua and Barbuda</option>
<option value=”Argentina”>Argentina</option>
<option value=”Armenia “>Armenia </option>
<option value=”Aruba”>Aruba</option>
<option value=”Australia”>Australia</option>
<option value=”Austria”>Austria</option>
<option value=”Azerbaidjan”>Azerbaidjan</option>
<option value=”Bahamas”>Bahamas</option>
<option value=”Bahrain”>Bahrain</option>
<option value=”Bangladesh”>Bangladesh</option>
<option value=”Barbados”>Barbados</option>
<option value=”Belarus”>Belarus</option>
<option value=”Belgium”>Belgium</option>
<option value=”Belize”>Belize</option>
<option value=”Bermuda”>Bermuda</option>
<option value=”Bhutan”>Bhutan</option>
<option value=”Bolivia”>Bolivia</option>
<option value=”Bosnia and Herzegovina”>Bosnia and Herzegovina</option>
<option value=”Brazil”>Brazil</option>
<option value=”Brunei”>Brunei</option>
<option value=”Bulgaria”>Bulgaria</option>
<option value=”Cambodia”>Cambodia</option>
<option value=”Canada”>Canada</option>
<option value=”Cape Verde”>Cape Verde</option>
<option value=”Cayman Islands”>Cayman Islands</option>
<option value=”Chile”>Chile</option>
<option value=”China”>China</option>
<option value=”Christmans Islands”>Christmans Islands</option>
<option value=”Cocos Island”>Cocos Island</option>
<option value=”Colombia”>Colombia</option>
<option value=”Cook Islands”>Cook Islands</option>
<option value=”Costa Rica”>Costa Rica</option>
<option value=”Croatia”>Croatia</option>
<option value=”Cuba”>Cuba</option>
<option value=”Cyprus”>Cyprus</option>
<option value=”Czech Republic”>Czech Republic</option>
<option value=”Denmark”>Denmark</option>
<option value=”Dominica”>Dominica</option>
<option value=”Dominican Republic”>Dominican Republic</option>
<option value=”Ecuador”>Ecuador</option>
<option value=”Egypt”>Egypt</option>
<option value=”El Salvador”>El Salvador</option>
<option value=”Estonia”>Estonia</option>
<option value=”Falkland Islands”>Falkland Islands</option>
<option value=”Faroe Islands”>Faroe Islands</option>
<option value=”Fiji”>Fiji</option>
<option value=”Finland”>Finland</option>
<option value=”France”>France</option>
<option value=”French Guyana”>French Guyana</option>
<option value=”French Polynesia”>French Polynesia</option>
<option value=”Gabon”>Gabon</option>
<option value=”Germany”>Germany</option>
<option value=”Gibraltar”>Gibraltar</option>
<option value=”Georgia”>Georgia</option>
<option value=”Greece”>Greece</option>
<option value=”Greenland”>Greenland</option>
<option value=”Grenada”>Grenada</option>
<option value=”Guadeloupe”>Guadeloupe</option>
<option value=”Guatemala”>Guatemala</option>
<option value=”Guinea-Bissau”>Guinea-Bissau</option>
<option value=”Guinea”>Guinea</option>
<option value=”Haiti”>Haiti</option>
<option value=”Honduras”>Honduras</option>
<option value=”Hong Kong”>Hong Kong</option>
<option value=”Hungary”>Hungary</option>
<option value=”Iceland”>Iceland</option>
<option value=”India”>India</option>
<option value=”Indonesia”>Indonesia</option>
<option value=”Ireland”>Ireland</option>
<option value=”Israel”>Israel</option>
<option value=”Italy”>Italy</option>
<option value=”Jamaica”>Jamaica</option>
<option value=”Japan”>Japan</option>
<option value=”Jordan”>Jordan</option>
<option value=”Kazakhstan”>Kazakhstan</option>
<option value=”Kenya”>Kenya</option>
<option value=”Kiribati “>Kiribati </option>
<option value=”Kuwait”>Kuwait</option>
<option value=”Kyrgyzstan”>Kyrgyzstan</option>
<option value=”Lao People’s Democratic Republic”>Lao People’s Democratic
Republic</option>
<option value=”Latvia”>Latvia</option>
<option value=”Lebanon”>Lebanon</option>
<option value=”Liechtenstein”>Liechtenstein</option>
<option value=”Lithuania”>Lithuania</option>
<option value=”Luxembourg”>Luxembourg</option>
<option value=”Macedonia”>Macedonia</option>
<option value=”Madagascar”>Madagascar</option>
<option value=”Malawi”>Malawi</option>
<option value=”Malaysia “>Malaysia </option>
<option value=”Maldives”>Maldives</option>
<option value=”Mali”>Mali</option>
<option value=”Malta”>Malta</option>
<option value=”Marocco”>Marocco</option>
<option value=”Marshall Islands”>Marshall Islands</option>
<option value=”Mauritania”>Mauritania</option>
<option value=”Mauritius”>Mauritius</option>
<option value=”Mexico”>Mexico</option>
<option value=”Micronesia”>Micronesia</option>
<option value=”Moldavia”>Moldavia</option>
<option value=”Monaco”>Monaco</option>
<option value=”Mongolia”>Mongolia</option>
<option value=”Myanmar”>Myanmar</option>
<option value=”Nauru”>Nauru</option>
<option value=”Nepal”>Nepal</option>
<option value=”Netherlands Antilles”>Netherlands Antilles</option>
<option value=”Netherlands”>Netherlands</option>
<option value=”New Zealand”>New Zealand</option>
<option value=”Niue”>Niue</option>
<option value=”North Korea”>North Korea</option>
<option value=”Norway”>Norway</option>
<option value=”Oman”>Oman</option>
<option value=”Pakistan”>Pakistan</option>
<option value=”Palau”>Palau</option>
<option value=”Panama”>Panama</option>
<option value=”Papua New Guinea”>Papua New Guinea</option>
<option value=”Paraguay”>Paraguay</option>
<option value=”Peru “>Peru </option>
<option value=”Philippines”>Philippines</option>
<option value=”Poland”>Poland</option>
<option value=”Portugal “>Portugal </option>
<option value=”Puerto Rico”>Puerto Rico</option>
<option value=”Qatar”>Qatar</option>
<option value=”Republic of Korea Reunion”>Republic of Korea Reunion</option>
<option value=”Romania”>Romania</option>
<option value=”Russia”>Russia</option>
<option value=”Saint Helena”>Saint Helena</option>
<option value=”Saint kitts and nevis”>Saint kitts and nevis</option>
<option value=”Saint Lucia”>Saint Lucia</option>
<option value=”Samoa”>Samoa</option>
<option value=”San Marino”>San Marino</option>
<option value=”Saudi Arabia”>Saudi Arabia</option>
<option value=”Seychelles”>Seychelles</option>
<option value=”Singapore”>Singapore</option>
<option value=”Slovakia”>Slovakia</option>
<option value=”Slovenia”>Slovenia</option>
<option value=”Solomon Islands”>Solomon Islands</option>
<option value=”South Africa”>South Africa</option>
<option value=”Spain”>Spain</option>
<option value=”Sri Lanka”>Sri Lanka</option>
<option value=”St.Pierre and Miquelon”>St.Pierre and Miquelon</option>
<option value=”St.Vincent and the Grenadines”>St.Vincent and the Grenadines</option>
<option value=”Sweden”>Sweden</option>
<option value=”Switzerland”>Switzerland</option>
<option value=”Syria”>Syria</option>
<option value=”Taiwan “>Taiwan </option>
<option value=”Tajikistan”>Tajikistan</option>
<option value=”Thailand”>Thailand</option>
<option value=”Trinidad and Tobago”>Trinidad and Tobago</option>
<option value=”Turkey”>Turkey</option>
<option value=”Turkmenistan”>Turkmenistan</option>
<option value=”Turks and Caicos Islands”>Turks and Caicos Islands</option>
<option value=”Ukraine”>Ukraine</option>
<option value=”UAE”>UAE</option>
<option value=”UK”>UK</option>
<option value=”USA”>USA</option>
<option value=”Uruguay”>Uruguay</option>
<option value=”Uzbekistan”>Uzbekistan</option>
<option value=”Vanuatu”>Vanuatu</option>
<option value=”Vatican City”>Vatican City</option>
<option value=”Vietnam”>Vietnam</option>
<option value=”Virgin Islands (GB)”>Virgin Islands (GB)</option>
<option value=”Virgin Islands (U.S.) “>Virgin Islands (U.S.) </option>
<option value=”Wallis and Futuna Islands”>Wallis and Futuna Islands</option>
<option value=”Yemen”>Yemen</option>
<option value=”Yugoslavia”>Yugoslavia</option>
</select>
</p>
<p>
<input name=”user_code” type=”text” size=”10″>
<img src=”pngimg.php” align=”middle”>&nbsp; </p>
<p align=”center”>
<input type=”submit” name=”Submit” value=”Register”>
</p>
</form></td>
</tr>
</table>
<div align=”left”></div>
</body>
</html>

setting.php

<?php
session_start();

if (!isset($_SESSION[‘user’]))
{
header(“Location: login.php”);
}

include (‘dbc.php’);

if ($_POST[‘Submit’]==’Change’)
{
$rsPwd = mysql_query(“select user_pwd from users where user_email=’$_SESSION[user]'”) or die(mysql_error());
list ($oldpwd) = mysql_fetch_row($rsPwd);

if ($oldpwd == md5($_POST[‘oldpwd’]))
{
$newpasswd = md5($_POST[‘newpwd’]);

mysql_query(“Update users
SET user_pwd = ‘$newpasswd’
WHERE user_email = ‘$_SESSION[user]’
“) or die(mysql_error());
header(“Location: settings.php?msg=Password updated…”);
} else
{ header(“Location: settings.php?msg=ERROR: Password does not match…”); }
}

?>
<h1>Settings</h1>
<p>
<?php if (isset($_GET[‘msg’])) { echo “<div class=\”msg\”> $_GET[msg] </div>”; } ?>
</p>
<h2>Change Password</h2>
<form action=”settings.php” method=”post” name=”form3″ id=”form3″>
<p>Old Password
<input name=”oldpwd” type=”password” id=”oldpwd”>
</p>
<p>New Password:
<input name=”newpwd” type=”password” id=”newpwd”>
</p>
<p>
<input name=”Submit” type=”submit” id=”Submit” value=”Change”>
</p>
</form>

Untuk cssnya

styles.css

.header {
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: none;
border-bottom-style: solid;
border-left-style: none;
border-top-color: #000000;
border-right-color: #000000;
border-bottom-color: #000000;
border-left-color: #000000;
}
.phpcode {
font-family: “Courier New”, Courier, mono;
font-size: 13px;
color: #000000;
background-color: f3f3f3;
}
.msg {
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
color: #FF0000;
background-color: #FFFFCC;
padding: 4px;
border: 1px dotted #FF9900;
font-weight: bold;

}

Untuk databasenya

CREATE TABLE `users` (
`id` int(20) NOT NULL auto_increment,
`full_name` varchar(200) collate latin1_general_ci NOT NULL default ”,
`user_name` varchar(200) collate latin1_general_ci NOT NULL default ”,
`user_pwd` varchar(200) collate latin1_general_ci NOT NULL default ”,
`user_email` varchar(200) collate latin1_general_ci NOT NULL default ”,
`activation_code` int(10) NOT NULL default ‘0’,
`joined` date NOT NULL default ‘0000-00-00’,
`country` varchar(100) collate latin1_general_ci NOT NULL default ”,
`user_activated` int(1) NOT NULL default ‘0’,
PRIMARY KEY (`id`)
)

semoga bermanfaat ya, kalau tidak mengerti Ask me,,hehehe

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: