For user identification,I need to send the url of localhost via mail in php codeigniter . . I also need to pass the token which I had generated for that user along with the url. My user need to be verified by clicking that link which must be identified by the corresponding token. And I have no idea about passing variables via url . . How could I proceed my code?
My code follows. .
<?php
class Site_model extends CI_Model
{
public function __construct()
{
parent:: __construct();
$this->load->database();
}
public function insert($token)
{
$data = array(
'name'=>$this->input->post('name'),
'email'=>$this->input->post('email'),
'phone'=>$this->input->post('phone'),
'date_of_birth'=>$this->input->post('dob'),
'user_type'=>$this->input->post('utype'),
'token'=>$token,
);
$this->db->insert('tbl_user',$data);
$email=$this->input->post('email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => '465',
'smtp_user' => 'someone@gmail.com',
'smtp_pass' => 'something',
'mailtype' => 'html',
'starttls' => true,
'newline' => "
"
);
$this->load->library('email',$config);
$this->email->From("someone@gmail.com");
$this->email->to($email);
$this->email->subject('test');
$this->email->message("worked");
$this->email->send();
if($this->email->send()) {
echo '<script>alert("Email sent successfully")</script>';
} else {
$this->email->print_debugger();
}
}
}
?>
To pass data along with a URL you can use URI segments.
In your situation the easiest thing to do would probably to be to use GET
parameters. To use these you would output the link as normal and then append a parameter to the end like:
http://yoursite.com/user/verify/**token**
This example would be for if you had a user
controller with a function called verify
. The method signature would be something like:
public function verify($token = NULL) { ... }
The last part of the URL will populate $token
which you can then use in the verify
function to check the user is valid and perform any actions you need to.
You could always re-route a URL to an alternative method through routes.php
if you needed to as well.
Simply pass this link with the token inserted into the email so that when the user clicks on it then the verify
method runs with the necessary parameters.