How to integrate OTP in CodeIgniter framework PHP
In this example we will discuss about how to integrate OTP in CodeIgniter framework PHP.
We use two file for send message in CodeIgniter framework PHP.
- OTP_send.php (CodeIgniter\application\controllers\OTP_send.php )
- sign_up.php (CodeIgniter\application\views\signup.php)
OTP_send.php
<?php
class Message_send extends CI_Controller
{
public function __construct()
{
//call CodeIgniter's default Constructorparent::__construct();
}
public function message()
{
//load registration view form$this->load->view('signup');
//Check submit button if($this->input->post('save'))
{
$phone=$this->input->post(‘phone’);
$user_message=$this->input->post(‘message’);
//Your authentication key$authKey = "3456655757gEr5a019b18";
//Multiple mobiles numbers separated by comma$mobileNumber = $phone; //Sender ID,While using route4 sender id should be 6 characters long. $senderId = "ABCDEF"; //Your message to send, Add URL encoding here. $rndno=rand(1000, 9999); $message = urlencode(“OTP number.".$rndno); //Define route $route = "route=4";
//Prepare you post parameters$postData = array(
'authkey' => $authKey,
'mobiles' => $mobileNumber,
'message' => $message,
'sender' => $senderId,
'route' => $route
);
//API URL$url="https://control.msg91.com/api/sendhttp.php";
// init the resource$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
//,CURLOPT_FOLLOWLOCATION => true));
//Ignore SSL certificate verificationcurl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response$output = curl_exec($ch);
//Print error if anyif(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo “OTP Sent Successfully !";
}
}
}
?>
sign_up.php
<!DOCTYPE html>
<html>
<head>
<title>Registration form</title>
</head>
<body>
<form method="post">
<table width="600" border="1" cellspacing="5" cellpadding="5">
<tr>
<td width="230">First Name </td>
<td width="329"><input type="text" name="name"/></td>
</tr>
<tr>
<td>Last Name </td>
<td><input type="text" name="phone"/></td>
</tr>
<tr>
<td>Email ID </td>
<td><input type="email" name="email"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="save" value="Save Data"/></td>
</tr>
</table>
</form>
</body>
</html>
Now run the program on your browser with the below URL:
http://localhost/CodeIgniter/index.php/OTP_send/signup
0 comments:
Post a Comment
Thanks