Friday, 8 April 2016

Monday, 4 April 2016

How to set up email verification using PHP CodeIgniter

Database Structure: 
CREATE TABLE `users` (
`userid` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(20) NOT NULL,
`last_name` varchar(20) NOT NULL,
`password` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
`is_verified` int(1) NOT NULL DEFAULT '0',
`hash` varchar(32) NOT NULL,
PRIMARY KEY (`userid`)
)
Controller: 


<?php
function insert_user() {
$this->data = array( //$data is a global variable
'first_name' => $_POST['fname'],
'last_name' => $_POST['lname'],
'email' => $_POST['email'],
'password' => md5($_POST['password']),
'hash' => md5(rand(0, 1000))
);
$this->user_registration_model->insert_record($this->data);
}
?>
<?php
function send_confirmation() {
$this->load->library('email'); //load email library
$this->email->from('admin@mysite.com', 'My Site'); //sender's email
$address = $_POST['email']; //receiver's email
$subject="Welcome to MySite!"; //subject
$message= /*-----------email body starts-----------*/
'Thanks for signing up, '.$_POST['fname'].'!
Your account has been created.
Here are your login details.
-------------------------------------------------
Email : ' . $_POST['email'] . '
Password: ' . $_POST['password'] . '
-------------------------------------------------
Please click this link to activate your account:
' . base_url() . 'index.php/user_registration/verify?' .
'email=' . $_POST['email'] . '&hash=' . $this->data['hash'] ;
/*-----------email body ends-----------*/
$this->email->to($address);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
}
?>


<?php
function verify() {
$result = $this->user_registration_model->get_hash_value($_GET['email']);
if($result){
if($result['hash']==$_GET['hash']){
$this->user_registration_model->verify_user($_GET['email']);
}
}
}
?>
Model: 

<?php
function verify_user($email) {
$data = array('is_verified' => 1);
$this->db->where('email', $email);
$this->db->update('users', $data);
}
?>

Saturday, 2 April 2016

How To Use JavaScript To Copy Text From One Field To Another

<html>
<head>
<title></title>

<script type="text/javascript">
function data_copy()
{

if(document.form1.copy[0].checked){
document.form1.add12.value=document.form1.add1.value;
document.form1.add22.value=document.form1.add2.value;
document.form1.city2.value=document.form1.city.value;
document.form1.state2.value=document.form1.state.value;
}else{
document.form1.add12.value="";
document.form1.add22.value="";
document.form1.city2.value="";
document.form1.state2.value="";

}

}

</script>
</head>


<body bgcolor="#ffffff" >
<table width='500' border='0' cellspacing='1' cellpadding='0'>
<form name=form1 method=post action='http://www.plus2net.com'>
<tr><td colspan=2><b>Ofice Address</b></td></tr>
<tr><td >Address 1</td><td><input type=text name=add1></td></tr>
<tr><td >Address 2</td><td><input type=text name=add2></td></tr>

<tr><td >City</td><td><input type=text name=city></td></tr>
<tr><td >State</td><td><input type=text name=state></td></tr>


<tr><td >
<b>Residence Address</b></td><td><input type=radio name=copy value='yes' onclick="data_copy()";>Same as above
<input type=radio name=copy value='no' onclick="data_copy()";>Not Same
</td></tr>
<tr><td >Address 1</td><td><input type=text name=add12></td></tr>

<tr><td >Address 2</td><td><input type=text name=add22></td></tr>
<tr><td >City</td><td><input type=text name=city2></td></tr>
<tr><td >State</td><td><input type=text name=state2></td></tr>


<tr><td colspan=2 align=center><input type=submit value=Submit> </form></td></tr>
</table>
</body>
</html>