
Complete integration guide for WebShost OTP SMS Service
Follow these simple steps to integrate OTP SMS API in your website or application
Select any plan from our pricing page and complete the purchase. You will receive your unique API Key in your client area.
Copy and paste this code in your PHP file. Replace YOUR_API_KEY with your actual API key.
<?php // ============================================= // WEBSHOST OTP SMS API INTEGRATION // API Endpoint: https://otp.webshost.in/ // ============================================= // Step 1: Get your API Key from client area $api_key = "YOUR_API_KEY_HERE"; // Step 2: User's mobile number and OTP $mobile = "1234567890"; // User's phone number (10 digits) $otp = rand(100000, 999999); // Generate 6-digit OTP // Step 3: Prepare API URL with otp.webshost.in domain $api_url = "https://otp.webshost.in/api-sms-v3.php?api_key=$api_key&number=$mobile&otp=$otp"; // Step 4: SSL context (disable verification for development only) $context_options = array( "ssl" => array( "verify_peer" => false, "verify_peer_name" => false, ) ); // Step 5: Send OTP via API $response = file_get_contents($api_url, false, stream_context_create($context_options)); // Step 6: Handle response with proper error checking if ($response === false) { die("β Error: Unable to connect to OTP API server"); } // Decode JSON response $result = json_decode($response, true); // Check if JSON decode was successful if (json_last_error() !== JSON_ERROR_NONE) { die("β Error: Invalid API response format"); } // Check response status if(isset($result['status']) && $result['status'] == 'success') { echo "β OTP sent successfully to $mobile"; // Store OTP in session for verification session_start(); $_SESSION['otp'] = $otp; $_SESSION['mobile'] = $mobile; $_SESSION['otp_expiry'] = time() + 300; // 5 minutes expiry } else { $error_msg = isset($result['message']) ? $result['message'] : 'Unknown error'; echo "β Failed to send OTP: " . $error_msg; } ?>
Full working example with OTP generation, sending, and verification.
<?php // File: send-otp.php session_start(); // Configuration $api_key = "YOUR_API_KEY_HERE"; // Get mobile number from POST request $mobile = $_POST['mobile'] ?? ''; // Validate mobile number if(empty($mobile) || !preg_match('/^[0-9]{10}$/', $mobile)) { echo json_encode(['status' => 'error', 'message' => 'Invalid mobile number']); exit; } // Generate 6-digit OTP $otp = rand(100000, 999999); // Prepare API URL $api_url = "https://otp.webshost.in/api-sms-v3.php?api_key=$api_key&number=$mobile&otp=$otp"; // Send request $context_options = array("ssl" => array("verify_peer" => false, "verify_peer_name" => false)); $response = file_get_contents($api_url, false, stream_context_create($context_options)); if ($response === false) { echo json_encode(['status' => 'error', 'message' => 'API connection failed']); exit; } $result = json_decode($response, true); // Store OTP in session if(isset($result['status']) && $result['status'] == 'success') { $_SESSION['otp'] = $otp; $_SESSION['mobile'] = $mobile; $_SESSION['otp_expiry'] = time() + 300; // 5 minutes echo json_encode(['status' => 'success', 'message' => 'OTP sent successfully']); } else { $error_msg = $result['message'] ?? 'Failed to send OTP'; echo json_encode(['status' => 'error', 'message' => $error_msg]); } ?> <?php // File: verify-otp.php session_start(); $otp = $_POST['otp'] ?? ''; $mobile = $_POST['mobile'] ?? ''; // Check if OTP exists and is not expired if(isset($_SESSION['otp']) && isset($_SESSION['mobile']) && isset($_SESSION['otp_expiry'])) { // Check expiry if(time() > $_SESSION['otp_expiry']) { echo json_encode(['success' => false, 'message' => 'OTP has expired']); exit; } // Verify OTP if($_SESSION['otp'] == $otp && $_SESSION['mobile'] == $mobile) { // OTP verified - clear session unset($_SESSION['otp']); unset($_SESSION['mobile']); unset($_SESSION['otp_expiry']); echo json_encode(['success' => true, 'message' => 'OTP verified successfully']); } else { echo json_encode(['success' => false, 'message' => 'Invalid OTP']); } } else { echo json_encode(['success' => false, 'message' => 'No OTP found. Please request a new one.']); } ?>
For modern websites, use this JavaScript code to send OTP without page refresh.
<script> // Function to send OTP using AJAX function sendOTP() { var mobile = document.getElementById('mobile').value; // Validate mobile number if(!mobile || mobile.length != 10 || !/^[0-9]+$/.test(mobile)) { alert('Please enter a valid 10-digit mobile number'); return; } // Show loading state document.getElementById('sendBtn').disabled = true; document.getElementById('sendBtn').innerHTML = 'β³ Sending...'; // Send AJAX request fetch('send-otp.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'mobile=' + mobile }) .then(response => response.json()) .then(data => { if(data.status == 'success') { document.getElementById('message').innerHTML = '<div class="alert alert-success">β OTP sent successfully! Check your mobile.</div>'; // Enable OTP input field document.getElementById('otp').disabled = false; document.getElementById('verifyBtn').disabled = false; // Start timer for resend startTimer(60); } else { document.getElementById('message').innerHTML = '<div class="alert alert-danger">β ' + data.message + '</div>'; } }) .catch(error => { document.getElementById('message').innerHTML = '<div class="alert alert-danger">β Error: ' + error.message + '</div>'; }) .finally(() => { document.getElementById('sendBtn').disabled = false; document.getElementById('sendBtn').innerHTML = 'π€ Send OTP'; }); } // Function to verify OTP function verifyOTP() { var mobile = document.getElementById('mobile').value; var otp = document.getElementById('otp').value; if(!otp || otp.length != 6) { alert('Please enter 6-digit OTP'); return; } document.getElementById('verifyBtn').disabled = true; document.getElementById('verifyBtn').innerHTML = 'β³ Verifying...'; fetch('verify-otp.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'mobile=' + mobile + '&otp=' + otp }) .then(response => response.json()) .then(data => { if(data.success) { document.getElementById('message').innerHTML = '<div class="alert alert-success">β OTP Verified Successfully!</div>'; // Redirect or show success page setTimeout(() => { window.location.href = 'dashboard.php'; }, 2000); } else { document.getElementById('message').innerHTML = '<div class="alert alert-danger">β ' + data.message + '</div>'; } }) .catch(error => { document.getElementById('message').innerHTML = '<div class="alert alert-danger">β Error: ' + error.message + '</div>'; }) .finally(() => { document.getElementById('verifyBtn').disabled = false; document.getElementById('verifyBtn').innerHTML = 'β Verify OTP'; }); } // Timer function for resend function startTimer(seconds) { var btn = document.getElementById('sendBtn'); btn.disabled = true; var timer = setInterval(function() { seconds--; btn.innerHTML = 'β³ Resend in ' + seconds + 's'; if(seconds <= 0) { clearInterval(timer); btn.disabled = false; btn.innerHTML = 'π€ Resend OTP'; } }, 1000); } </script>
Ready-to-use HTML form with OTP verification.
<!DOCTYPE html>
<html>
<head>
<title>OTP Verification - WebShost</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6 col-lg-4">
<div class="card shadow">
<div class="card-body p-4">
<h4 class="text-center mb-4">π± OTP Verification</h4>
<div id="message"></div>
<div class="mb-3">
<label class="form-label">Mobile Number</label>
<input type="tel" id="mobile"
class="form-control"
placeholder="Enter 10-digit number"
maxlength="10" required>
</div>
<button id="sendBtn" class="btn btn-primary w-100"
onclick="sendOTP()">
π€ Send OTP
</button>
<hr>
<div class="mb-3">
<label class="form-label">Enter OTP</label>
<input type="text" id="otp"
class="form-control"
placeholder="Enter 6-digit OTP"
maxlength="6" disabled>
</div>
<button id="verifyBtn" class="btn btn-success w-100"
onclick="verifyOTP()" disabled>
β
Verify OTP
</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Add JavaScript functions here (from Step 4)
</script>
</body>
</html>
For Node.js applications, use this code.
// Node.js with axios const axios = require('axios'); // Configuration const API_KEY = 'YOUR_API_KEY_HERE'; const API_URL = 'https://otp.webshost.in/api-sms-v3.php'; // Function to send OTP async function sendOTP(mobile, otp) { try { const response = await axios.get(API_URL, { params: { api_key: API_KEY, number: mobile, otp: otp }, httpsAgent: new (require('https').Agent)({ rejectUnauthorized: false }) }); return response.data; } catch (error) { console.error('Error sending OTP:', error.message); return { status: 'error', message: error.message }; } } // Express.js route example const express = require('express'); const app = express(); app.use(express.json()); app.post('/api/send-otp', async (req, res) => { const { mobile } = req.body; // Validate mobile if (!mobile || !/^[0-9]{10}$/.test(mobile)) { return res.status(400).json({ status: 'error', message: 'Invalid mobile number' }); } // Generate OTP const otp = Math.floor(100000 + Math.random() * 900000); // Send OTP const result = await sendOTP(mobile, otp); if (result.status === 'success') { // Store OTP in session/database res.json({ status: 'success', message: 'OTP sent successfully' }); } else { res.status(500).json(result); } }); app.listen(3000, () => { console.log('Server running on port 3000'); });
For Python applications, use this code.
# Python with requests import requests import random import json # Configuration API_KEY = "YOUR_API_KEY_HERE" API_URL = "https://otp.webshost.in/api-sms-v3.php" def send_otp(mobile, otp): """Send OTP to mobile number""" params = { 'api_key': API_KEY, 'number': mobile, 'otp': otp } try: response = requests.get(API_URL, params=params, verify=False) response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: return {'status': 'error', 'message': str(e)} # Flask example from flask import Flask, request, jsonify, session import time app = Flask(__name__) app.secret_key = 'your-secret-key-here' @app.route('/api/send-otp', methods=['POST']) def send_otp_route(): data = request.get_json() mobile = data.get('mobile', '') # Validate mobile if not mobile or not mobile.isdigit() or len(mobile) != 10: return jsonify({'status': 'error', 'message': 'Invalid mobile number'}), 400 # Generate OTP otp = random.randint(100000, 999999) # Send OTP result = send_otp(mobile, otp) if result.get('status') == 'success': # Store OTP in session session['otp'] = otp session['mobile'] = mobile session['otp_expiry'] = time.time() + 300 return jsonify({'status': 'success', 'message': 'OTP sent successfully'}) else: return jsonify(result), 500 @app.route('/api/verify-otp', methods=['POST']) def verify_otp_route(): data = request.get_json() mobile = data.get('mobile', '') otp = data.get('otp', '') # Check if OTP exists in session if 'otp' not in session or 'mobile' not in session: return jsonify({'success': False, 'message': 'No OTP found'}), 400 # Check expiry if time.time() > session.get('otp_expiry', 0): session.clear() return jsonify({'success': False, 'message': 'OTP has expired'}), 400 # Verify OTP if session['otp'] == int(otp) and session['mobile'] == mobile: session.clear() return jsonify({'success': True, 'message': 'OTP verified successfully'}) else: return jsonify({'success': False, 'message': 'Invalid OTP'}), 400 if __name__ == '__main__': app.run(debug=True, port=5000)
https://otp.webshost.in/ for production.β Success Response:
β Error Response:
YOUR_API_KEY with actual keyContact our support team at support@webshost.com or visit our client area for API documentation.
π API Endpoint: https://otp.webshost.in/api-sms-v3.php
Deliver OTP messages instantly with high-speed and secure infrastructure, ensuring reliable authentication for your users.
Start sending OTP SMS without the hassle of DLT registration. Quick setup and instant activation for your business.
Send OTP SMS across all telecom networks in India with maximum delivery success and minimal delay.
Integrate our OTP SMS API Ψ¨Ψ³ΩΩΩΨ© into your website or app with simple documentation and developer-friendly endpoints.
Monitor all OTP requests with detailed logs, delivery reports, and tracking system to ensure complete transparency and control.
Manage your SMS campaigns with a powerful control panel and get expert support for setup, API integration, and troubleshooting.
Fast delivery. Secure API. Reliable OTP verification for your business and applications.
Buy OTP SMS NowDeliver OTP messages instantly with our high-performance SMS gateway. Webshost ensures fast delivery, secure transmission, and uninterrupted service across all Indian networks.
Send OTP SMS across all telecom operators in India with high delivery success rates and minimal delays for seamless user verification.
Easily integrate our OTP SMS API into your website or mobile app with simple documentation and developer-friendly endpoints.
Our expert team is always available to help you with API integration, setup, troubleshooting, and delivery issues β ensuring your OTP system runs smoothly at all times.
Contact NowOTP SMS service allows you to send One-Time Passwords instantly to users for secure login, verification, and transactions. It ensures fast delivery, high security, and seamless authentication for websites, apps, and online platforms.
Talk to SMS Expert
Our OTP SMS API is simple to integrate with any website or mobile app. With HTTPS API, real-time delivery tracking, and no DLT registration hassle, you can start sending OTPs within minutes without complex setup.
Get OTP SMS Now