php div refreshed by javascript looses php session variables after 1st reload

343
January 12, 2017, at 08:07 AM

main.php

<?php
session_start();
echo "<div id='buttons'>
include "buttons.php";
echo "</div>";

Javascript

function refreshButtons(){
    $('#buttons').load(document.URL +  ' #buttons');
}

buttons.php

session_start();
$a=checkbuttons($_SESSION['userid']);
if ($a=="false") {
echo "<button type='submit' class='btn btn-danger btn-lg'>Return to Main</button>";
}
else {
echo "<button type='submit' class='btn btn-success btn-lg'>Proceed</button>";
}

I have a main page that has a div that gets refresh every 10 seconds. It loads buttons.php that checks mysql database returning either true or false based on users session id. The page loads fine the 1st time, all variables are ok. The problem I have is $_SESSION['userid'] is empty after the 1st time javascript refreshes the div. And ofcourse after that the results from the query are always false. Session id stays the same, that I have already checked. I'm at a loss what to check next here. buttons.php starts it's own session every time it loads but still the variable is empty.

Rent Charter Buses Company
READ ALSO
PHP echo json with key value

PHP echo json with key value

why does this code not work correctly or what am I doing incorrectly?

480
Woocommerce Excluding Certain Category from Shop Page

Woocommerce Excluding Certain Category from Shop Page

Trying to exclude a single category from my WooCommerce's Shop Page

377
Keeping Track PHP Sessions

Keeping Track PHP Sessions

This is a simple PHP Code:

317