Thursday, December 11, 2014

Register Confirm Using Mail

create 4 page

1. login.php
2. register.php
3. verify.php
4. Confirm.php


Login.php                                                                                                          
                                                                                                                                

 <html>


</html> 



register.php                                                                                                          
                                                                                                                                  

<?php 
if(isset($_POST['submitform'])){

$name = trim(mysql_escape_string($_POST['name']));
$email = trim(mysql_escape_string($_POST['email']));
$passwords = trim(mysql_escape_string($_POST['pwd']));
$password = md5($passwords);

$query_verify_email = "SELECT * FROM register WHERE email ='$email' and isactive = 1";
$verified_email = mysqli_query($con,$query_verify_email);
if (!$verified_email) {
echo ' System Error';
}
if (mysqli_num_rows($verified_email) == 0) {
// Generate a unique code:
$hash = md5(uniqid(rand(), true));
$query_create_user = "INSERT INTO `register` ( `name`, `email`, `password`, `hash`) VALUES ( '$name', '$email', '$password', '$hash')";
$created_user = mysqli_query($con,$query_create_user);
if (!$created_user) {
echo 'Query Failed ';
}

if (mysqli_affected_rows($con) == 1) { //If the Insert Query was successfull.

$subject = 'Activate Your Email';

$headers = "From: admin@php999.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$url= BASE_PATH . '/verify.php?email=' . urlencode($email) . "&key=$hash";

$message ='<p>To activate your account please click on Activate buttton</p>';
$message.='<table cellspacing="0" cellpadding="0"> <tr>';
$message .= '<td align="center" width="300" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;

color: #ffffff; display: block;">';

$message .= '<a href="'.$url.'" style="color: #ffffff; font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none;

line-height:40px; width:100%; display:inline-block">Click to Activate</a>';
$message .= '</td> </tr> </table>';

mail($email, $subject, $message, $headers);

echo '<div>A confirmation email
has been sent to <b>'. $email.' </b> Please click on the Activate Button to Activate your account </div>';
} else { // If it did not run OK.
echo '<div>You could not be registered due to a system
error. We apologize for any
inconvenience.</div>';
}
}
else{
echo '<div>Email already registered</div>';}
}

?>


verify.php                                                                                                          
                                                                                                                           


<?php
$email = trim(mysql_escape_string($_GET['email']));

$key = trim(mysql_escape_string($_GET['key']));

$query_verify_email = "SELECT * FROM register WHERE email ='$email' and isactive = 1";
$result_verify_email = mysqli_query($con,$query_verify_email);

if (mysqli_num_rows($result_verify_email) == 1)
{
echo '<div>Your Account already exists. Please <a href="login.html">Login Here</a></div>';

}
else
{

if (isset($email) && isset($key))

{

mysqli_query($con, "UPDATE register SET isactive=1 WHERE email ='".$email."' AND hash='".$key."' ") or die(mysql_error());

if (mysqli_affected_rows($con) == 1)
{
echo '<div>Your Account has been activated. Please <a href="login.html">Login Here</a></div>';

} else
{
echo '<div>Account couldnot be activated.</div>';

}
}
mysqli_close($con);

}?>


No comments:

Post a Comment

GitHub repository using Git Bash command

  To add a project to a GitHub repository using Git Bash command line, you can follow these steps: Create a new repository on GitHub by logg...