// first page
<?php
session_start();
// $var_value =$_SESSION['orderidno'];
// $var_value =$_GET['orderur'];
if(isset($_POST['login']))
{
$mobileNo=$_POST['mobileNo'];
$passWord=$_POST['passWord'];
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'here is my api url',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response_details = curl_exec($curl);
$data_details=json_decode($response_details,TRUE);
$data1_details=json_decode($response_details);
curl_close($curl);
$res=$data_details['ispasswordMatched'];
if($res)
{
$_SESSION['loggedin'] = "true";
$_SESSION['loggedinnumber'] = $mobileNo;
foreach($data_details['content'] as $result)
{
$_SESSION['vendorname'] = $result['vendorname'];
$_SESSION['vendorkey'] = $result['vendorkey'];
$_SESSION['userkey'] = $result['key'];
//here i have been storing my api result values in session
}
echo "<script> location.href='userdetails.php'; </script>";
}
else if($mobileNo!="")
{
$empty=$data_details['message'];
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP HTML TABLE DATA SEARCH</title>
<style>
table,tr,th,td
{
border: 1px solid black;
}
div#searcharea {
text-align: center;
}
</style>
</head>
<body>
<form id="search_form" method="post" action="login.php" >
<!--<h4>Search Customer / Customer Order</h4>-->
<div>
<input id="mobilenumbervalue" style="width: 88%; margin-top: 22px" type="text" name="mobileNo" placeholder="Enter the Mobile Number" pattern="[1-9]{1}[0-9]{9}" required>
<input id="orderidvalue" style="width: 88%; margin-top: 22px" type="password" name="passWord" placeholder="Enter the password" required>
<br>
<p id="mobileError" style="color: red;"><?php echo $empty?></p>
<p id="orderError" style="color: red;"><?php echo $emptyOrder?></p>
</div>
<div>
<Button style="background: #fdd110; width: 35%;
height: 39px; border: #fdd110; margin-top: 15px;" id="userdataSearchButton" type="submit" name="login" >Log In</Button>
</div>
</form>
<script type="text/javascript">
function myFunction() {
alert("work in progress");
}
function required()
{
var empt = document.forms["form1"]["valueToSearch"].value;
if (empt == "")
{
alert("Please input a Value");
return false;
}
}
</script>
</body>
</html>
//end of first page
//second page
//userdetails.php
<?php
session_start();
$var_value =$_SESSION['loggedin'];
if($var_value!="true")
{
echo "the user doesn't exist";
}
else
{
echo "the user is exists";
}
?>
//here will be my second page html
//end of second page
Since you experienced a different behaviour in two different ambients, I would check the php configuration in the new server for session handling, that is 'session.cookie_httponly' (since you use javascript for redirection), 'session.use_cookies' and 'session.use_only_cookies' .
Besides, I would suggest to force-close the session before doing a redirection, to ensure the session actually writes the data before the new page loads.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.