I am displaying some information based upon the users day of the week. [[Getting the server side day of the week can display the wrong day's information depending on the timezone difference.]] The problem is, with this code, the session variable is not getting set on the first page load. Every next page load, it is set.
The user is visiting the home page and there is no login required.
I would like to be able to get the UserDay variable before the page is loaded, or shortly after it is loaded so that the user does not have to see the wrong information the first time around.
session.php (Main Page)
session_start();
$userday= $_SESSION['userday'];
document.ready (loaded in header)
$(document).ready(function() {
var now = new Date();
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var UserDay = days[ now.getDay() ];
$.ajax({
type: "GET",
url: "userday.php",
data: 'userday='+ UserDay,
success: function(){
}
});
});
userday.php
<?php
session_start();
$_SESSION['userday'] = $_GET['userday'];
?>