![](/img/trans.png)
[英]How to use $_SESSION to pass on values from multiple pages and $_POST together
[英]how to use session in multiple pages
// 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
由於您在兩種不同的環境中經歷了不同的行為,我會檢查新服務器中的 php 配置以進行會話處理,即“session.cookie_httponly” (因為您使用 javascript 進行重定向)、 “session.use_cookies”和“ session.cookies” 。 use_only_cookies' 。
此外,我建議在進行重定向之前強制關閉會話,以確保會話在新頁面加載之前實際寫入數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.