CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New

How to integrate OTP in CodeIgniter framework PHP


Still unable to integrate OTP. Hire an expert at only INR 1500.00/- Rupees Or $20. Please contact us info@studentstutorial.com, +91 9437911966

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.

  1. OTP_send.php (CodeIgniter\application\controllers\OTP_send.php )
  2. 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 Constructor*/
	parent::__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 verification*/
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
/*get response*/
$output = curl_exec($ch);
/*Print error if any*/
if(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

Still unable to integrate OTP. Hire an expert at only INR 1500.00/- Rupees Or $20. Please contact us info@studentstutorial.com, +91 9437911966