Dark

Light

Dark

Light

Scroll to top

How to Set Cookie and OTP in php?


//cookie method
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day

//get cookie content
if(!isset($_COOKIE[$cookie_name])) {
    echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
    echo "Cookie '" . $cookie_name . "' is set!<br>";
    echo "Value is: " . $_COOKIE[$cookie_name];
}

//otp method 
$otp = mt_rand(10000,99999);
echo 'Your otp is'. $otp;

You can set otp as cookie and then retrieve to match during login.

Author avatar
Amitpal Singh
https://amitpalsingh.com

Post a comment

Your email address will not be published. Required fields are marked *