I am trying to do an ajax post for an e-commerce site.
So what I did was do an ajax post, when user click to "Add to cart" it will do the ajax post to the following php page with the code
<?php
include 'inc/session.php';
$product_id = $_POST['product_id'];
$quantity = $_POST['quantity'];
if($_POST['action'] == "add") {
$_SESSION[$product_id]['quantity'] = $quantity;
$_SESSION["hello"] = "WORLD";
//if add success return 111, else echo something else
echo "111";
}
if($_POST['action'] == "remove") {
$_SESSION[$product_id]['quantity'] = $quantity;
//if add success return 111, else echo something else
echo "111";
}
?>
When I try to go to other page after the ajax post, I did
print_r($_SESSION);
But it return empty array.
Everything is done within the same domain, same server.
Thanks for helping!
Below is my session file
<?php
ini_set("session.cache_limiter", "must-revalidate");
session_name("sess1");
session_start();
?>