おそらく、ユーザーがクリックして次の URL に移動するときに、いくつかの php コーディングを使用してCookieを設定できます。例えば:
<?php
setcookie("Brand", "brand_value", time()+3600); // Expires in one hour
?>
次に、次のページで次のようにブランドを取得できます。
<?php echo $_COOKIE["Brand"]; ?> // echoes the value of Brand
より詳細には、これを試すことができます:
Main_File
<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>
cookie.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"];
?>