当用户点击转到下一个 url 时,也许您可以使用一些 php 编码来设置cookie 。例如:
<?php
setcookie("Brand", "brand_value", time()+3600); // Expires in one hour
?>
然后在下一页您可以检索品牌,如下所示:
<?php echo $_COOKIE["Brand"]; ?> // echoes the value of Brand
更详细地说,你可以试试这个:
主文件
<script>
$(document).ready(function(){
$('#submit-car').click(function(e){
e.preventDefault();
var brand = $('#brand option:selected').text();
var model = $('#model option:selected').text();
var size = $('#size option:selected').text();
// Ajax call to a cookies.php file, passing the values
$.get('cookies.php', { thebrand: brand, themodel: model, thesize: size },
function() {
// When the call has been completed, open next page
location.href ='index.php?s='+brand+'+'+model+'+'+size+'';
});
});
});
</script>
饼干.php
<?php
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// Get all the values
$theBrand = $_GET["thebrand"];
$theModel = $_GET["themodel"];
$theSize = $_GET["thesize"];
// Call the setTheCookies function, below
setTheCookies($theBrand, $theModel, $theSize);
// The setTheCookies function
function setTheCookies($theBrand, $theModel, $theSize)
{
setcookie("Brand", $theBrand, time()+3600);
setcookie("Model", $theModel, time()+3600);
setcookie("Size", $theSize, time()+3600);
}
}
?>
下一页
<?php
// Get all the values from the next page
$getBrand = $_COOKIE["Brand"];
$getModel = $_COOKIE["Model"];
$getSize = $_COOKIE["Size"];
?>