I'm trying to get session variables from one website to another. The website that has the variables is a shop, the other one a regular website.
I want to know on the regular website if the user is logged in (only if, I don't need to know on what account) and how many items the user has in their cart.
My plan was to achieve this with echoing a json object on a blank page and use jQuery.get on the other website in order to get the variables. The page in the shop (transferdata.php) does display the correct object, which is
{"logged":1,"cart":9}.
However, the page that retrieves this data (getdata.php) gets
{"logged":0,"cart":0}.
Code for transferdata.php (the file in the shopwebsite)
# Check login status
if ($ca->isLoggedIn()) {
$transferdata['logged'] = 1;
} else {
$transferdata['logged'] = 0;
}
# Get amount of items in a cart
$transferdata['cart'] = count ($_SESSION['cart']['products']) + count ($_SESSION['cart']['addons']) + count ($_SESSION['cart']['domains']);
# Display transferdata
echo json_encode($transferdata);
Code for getdata.php (the file in the regular website)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$.get( "https://**.*******.nl/transferdata.php", function( data ) {
$( ".result" ).html( data );
alert( "Load was performed." );
});
</script>
<div class="result"></div>
The shop is located in a folder of the regular website (the shop is on a subdomain). I'm trying to have a navigation in the regular website for the shop, so that users can easily go to the shop from the regular website. I need the "logged" to know if I need to show the normal navigation or the version for logged in users, and I need the cartitemcount to show in "Cart (0)" in the navigation
Can anyone help me fix this? If the best answer isn't a json object, I'm open for suggestions.