BoomBox Community

Software Push - Web | IT | Coding | Tutorial

  • HOW TO
  • TUTORIALS
    • DEMO
    • HTML
    • CSS
  • JAVASCRIPT
    • JQUERY
    • Ajax
    • REACT NATIVE
    • Node.js
  • PHP
    • CODEIGNITER
    • LARAVEL
    • WORDPRESS
    • Oracle
  • PYTHON
    • HTACCESS
  • Snippets
    • Alert
  • Chat Gpt
  • Donate
sections
  • Uncategorized
  • Videos
BoomBox Community

Software Push - Web | IT | Coding | Tutorial

  1. Home
  2. HOW TO
  3. OTP login PHP Ajax
2 months ago 2 months ago

HOW TO, PHP

OTP login PHP Ajax


Developer
by Developer 2 months ago2 months ago
0

OTP (One-Time Password) login is a method of authentication that uses a unique code, sent via text message or email, to confirm a user’s identity. This method provides an additional layer of security, as the code can only be used once and expires after a certain amount of time.

Example 1

Here we are using 3 file for delete data from MySql database using Ajax.

  1. database.php
  2. delete_ajax.php
  3. view.php

Table user_data

CREATE TABLE `otp` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `email` varchar(100) NOT NULL,
  `phone` varchar(100) NOT NULL
) 

database.php

<?php
	$servername = "localhost";
	$username = "root";
	$password = "";
	$db="school";
    $conn = mysqli_connect($servername, $username, $password,$db);
?>

index.php

 <!DOCTYPE html>
<html>
<title>Form</title>
<head>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
</head>
<body>
<form action="" method="post" id="form-search">
   
    Phone:<input class="input" type="text" placeholder="phone" name="phone" id="phone" required><br><br>
    <div id="otp_section" style="display:none;">
		OTP:<input class="input" type="text" placeholder="OTP" name="otp" id="otp" required><br><br>
    </div>
    <button  type="button" name="btn-save" id="continue">Continue</button>
    <button  type="button" name="login" id="login" style="display:none;">Submit</button>
</form>
<script>
$(document).on('click','#continue',function(e) {
    var phone = $('#phone').val();
    $.ajax({
         data: {
					type: 2,
					phone: phone
								
				},
         type: "post",
         url: "login_ajax.php",
				success: function(dataResult){
					var dataResult = JSON.parse(dataResult);
					if(dataResult.statusCode==200){
						$("#otp_section").show();
						$("#continue").hide();
						$("#login").show();
						
					}
					else{
					    alert(dataResult);
					}
					
				}
	});
	
});
$(document).on('click','#login',function(e) {
    var otp = $('#otp').val();
    $.ajax({
				data:   {
							type: 3,
							otp: otp
										
						},
				type: "post",
				url : "login_ajax.php",
				success: function(dataResult){
					var dataResult = JSON.parse(dataResult);
					if(dataResult.statusCode==200){
						alert("Login successful !");
					}
					else{
					    alert("Invalid OTP !");
					}
					
				}
	});
	
});
</script>
</body>
</html>

login_ajax.php

<?php
	session_start();
	error_reporting(0);
	include 'database.php';
	if($_POST["type"]==2){
		    $phone=$_POST['phone'];
			$result = mysqli_query($connection,"SELECT * FROM otp WHERE phone='$phone'");
			$row  = mysqli_fetch_array($result);
			if(is_array($row)){
				$authKey = "53ApW6gJgEr5a019b18";
				$mobileNumber = $phone;
				$senderId = "ABCDEF";
				$rndno=rand(100000, 999999);
				$message = urlencode("otp number.".$rndno);
				$route = "route=4";
				$postData = array(
					'authkey' => $authKey,
					'mobiles' => $mobileNumber,
					'message' => $message,
					'sender' => $senderId,
					'route' => $route
				);
				$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 */
				));
				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);
				$_SESSION['otp']=$rndno;
				echo json_encode(array("statusCode"=>200));
			}
			else{ 
				echo "Mobile number not exist !";
			}
	}
	if($_POST["type"]==3){
		if($_POST["otp"]==$_SESSION['otp']){
			echo json_encode(array("statusCode"=>200));
		}
		else{
			echo json_encode(array("statusCode"=>201));
		}
	}
?>
Post Views: 29

Post Pagination

  • Previous PostPrevious
  • Next PostNext

otp login php ajax

Like it? Share with your friends!

0
Developer

Posted by Developer

You may also like

  • Ajax, JQUERY, PHPajax otp, otp login php ajax, php login with otp

    OTP login PHP Ajax

0 Comments

Cancel reply

You must be logged in to post a comment.

  • Previous Post
    MERGE TWO LISTS INTO A DICTIONARY PYTHON
    by Developer
  • Next Post
    How to validate email in JavaScript
    by Developer

More From: HOW TO

  • HOW TO, PHPlogin system with oops, php login with oops, PHP oops login

    How to make login system using php opps method

  • HOW TO, JAVASCRIPTjavascript motion control, Motion Controls In The Browser, Motion Controls In The Browser with javascript

    Motion Controls In The Browser using javascript

  • Ajax, HOW TO, HTML, JQUERY, PHPjquery notifiction, Notification system jQuery, php, php notifiction without reload page

    Notification system using jQuery, PHP, and MySQL

  • HOW TO, PYTHONMERGE TWO LISTS INTO A DICTIONARY PYTHON

    MERGE TWO LISTS INTO A DICTIONARY PYTHON

  • HOW TO, PHPotp login php ajax

    OTP login PHP Ajax

  • HOW TO, Oracle, PHPFetch Data using Oracle and PHP

    Fetch Data using Oracle and PHP

DON'T MISS

  • Uncategorized

    Python read and write csv file

  • HTAccess

    Active Gzip Compression using htaccess

  • JQUERYScroll Page Horizontally, Scroll Page Horizontally using jquery

    Scroll Page Horizontally With Mouse Wheel

  • PHPIntegrate Paytm Payment Gateway, payment gateway in php, paytm payment, paytm payment gateway in php

    How to Integrate Paytm Payment Gateway In PHP?

  • LARAVEL, PHPScaffolding in Laravel, Scaffolding in Laravel 9, Vue Js

    how Scaffolding using Vue Js Auth in Laravel 9

  • JAVASCRIPT, Node.jsChat Application, Chat Application With js express, Chat Application With node js, Chat Application With Socket.io

    Build Chat Application With Socket.io Using Node Js Express

Recent Post

  • Python read and write csv file

    2 weeks ago2 weeks ago
  • Active Gzip Compression using htaccess

    2 months ago2 months ago
  • Scroll Page Horizontally With Mouse Wheel

    2 months ago2 months ago
  • How to Integrate Paytm Payment Gateway In PHP?

    2 months ago2 months ago
  • how Scaffolding using Vue Js Auth in Laravel 9

    2 months ago2 months ago
  • Build Chat Application With Socket.io Using Node Js Express

    2 months ago2 months ago

add csv to mysql with codeigniter add Data From Excel & CSV to mysql Using Codeigniter android app android vpn app app Build a Node.js API Proxy call a API using PHP CURL change the color of command prompt Chat Application Chat Application With js express Chat Application With node js Chat Application With Socket.io ChatGPT Job Interview ChatGPT Job Interview for a Scrum Master ChatGPT Job Interview question Clear input value using Jquery convert a date number string to word convert image to pdf convert image to pdf using php css csv file into array in php date number to string detect input field value changes in angular download file from url using jquery download file using jquery Downloading files on Onedrive with PHP Fetch Data using Oracle and PHP google map google map api google map api with javascript hangman game with javascript How to add Data From Excel how to change the color of command prompt using python how to clear input value using jquery how to download file from url how to download file from url using jquery how to download file using jquery how to make game how to make game with javascript how to make hangman game with javascript how to make vpn app how to pause play video on hover how to read csv file How to Upload And save File How to Upload And save File To PostgreSQL with PHP how to upload file in php html html css http request javascript Image Illustration Filter using css Insert Data Using Oracle Insert Data Using Oracle PHP Integrate Paytm Payment Gateway javascript javascript motion control jquery jquery ajax jquery notifiction jquery validation login system with oops Motion Controls In The Browser Motion Controls In The Browser with javascript mouce hover video play Notification system jQuery otp login php ajax payment gateway in php paytm payment paytm payment gateway in php php php curl php login with oops php notifiction without reload page PHP oops login python python AI react react native read csv file into an array remove class from foreach using jquery remove class using jquery remove class with jquery remove duplicate value from array remove duplicate value from array in php remove duplicate value from array using php rotate text rotate text in css rotate text using html and css Scaffolding in Laravel Scaffolding in Laravel 9 Scroll Page Horizontally Scroll Page Horizontally using jquery Stock Prediction AI with python Uploading and Downloading files on Onedrive validate email validate email in JavaScript video play using javascript vonvert image to pdf with php vpm app with android Vue Js wordpress

  • Python read and write csv file

    Python read and write csv file

  • Active Gzip Compression using htaccess

    Active Gzip Compression using htaccess

  • Scroll Page Horizontally With Mouse Wheel

    Scroll Page Horizontally With Mouse Wheel

  • How to Integrate Paytm Payment Gateway In PHP?

    How to Integrate Paytm Payment Gateway In PHP?

  • how Scaffolding using Vue Js Auth in Laravel...

    how Scaffolding using Vue Js Auth in Laravel...

  • Build Chat Application With Socket.io Using Node Js...

    Build Chat Application With Socket.io Using Node Js...

  • How to make login system using php opps...

    How to make login system using php opps...

  • A ChatGPT Job Interview for a Scrum Master...

    A ChatGPT Job Interview for a Scrum Master...

  • How To Build a Node.js API Proxy Using...

    How To Build a Node.js API Proxy Using...

  • Motion Controls In The Browser using javascript

    Motion Controls In The Browser using javascript

  • Notification system using jQuery, PHP, and MySQL

    Notification system using jQuery, PHP, and MySQL

  • Stock Prediction AI with python

    Stock Prediction AI with python

  • python chatbot with complete source code

    python chatbot with complete source code

  • MERGE TWO LISTS INTO A DICTIONARY PYTHON

    MERGE TWO LISTS INTO A DICTIONARY PYTHON

  • OTP login PHP Ajax

    OTP login PHP Ajax

  • How to validate email in JavaScript

    How to validate email in JavaScript

  • Fetch Data using Oracle and PHP

    Fetch Data using Oracle and PHP

  • Insert Data Using Oracle PHP

    Insert Data Using Oracle PHP

  • About us
  • Advertise
  • Privacy Policy
© 2023 All Rights Reserved

log in

Become a part of our community!

Forgot password?
Don't have an account?
sign up

forgot password

Back to
log in

sign up

Back to
log in