I am saving OTP value in SESSION and using it in other file. File is getting called by AJAX POST request.
Unfortunately it is not accessible in other file. Here is the code where session value getting store.
<?php
session_start();
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
$mobile = '1234567890';
if(!empty($mobile)) {
function generateOtp1() {
return rand(1000, 9000);
}
$val = generateOtp1();
echo $val;
$_SESSION['otp'] = $val;
print_r ($_SESSION);
}
?>
Here is the second file where I am calling $_SESSION['otp']
:
<?php
session_start();
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
$errors = array(); // array to hold validation errors
$data = array();
print_r ($_SESSION);
?>
It is showing empty in the output:
Array
(
)
This is the output I am getting. What am I doing wrong?
PHP is enabled in webserver.
Session Support enabled
Registered save handlers files user
Registered serializer handlers php_serialize php php_binary wddx
PHP version is 7.