I have 2 pages. One, index.php with the following code:
<?php
if( isset( $_COOKIE['TzSelect'] ) )
{
header( 'Location: http://xasxx.dasxxx.com/feed.php');
}
?>
<html> ....
<form action='feed.php' method="post">
<select name="myvalue" id="SelectTimeZone">
<option value="Africa/Mbabane">Africa/Mbabane</option>
<option value="Africa/Mogadishu">Africa/Mogadishu</option>
<option value="Africa/Monrovia">Africa/Monrovia</option>
</select>
<input type="submit">
</form>
And, the feed.php code:
if( isset( $_COOKIE['TzSelect'] ) )
{
$myvalue = $_COOKIE["TzSelect"];
date_default_timezone_set($myvalue);
}
else
{
$number_of_days = 1000 ;
$date_of_expiry = time() + 60 * 60 * 24 * $number_of_days ;
setcookie( "TzSelect", myvalue, $date_of_expiry, "/" ) ;
}
Now, when you run the index.php, you select a timezone from the drop down, and when you submit, the feed.php loads with the date_default_timezone_set utilizing the selected value and doing further calculations. It's also set, much lower down the actual file (which does not have any effect on the cookie at all) to show EST as the standard time zone, so all calculations would be done in EST if something doesn't work right. Also, this is a first-time only choosing the time zone (which is why I am storing it in a cookie). So, what I have is on the index.php page the very first thing it does is checks if the cookie exists. If it does, it redirects to the feed.php page where the calculations are done based on the already preset value stored in the cookie. Now, the cookie is definitely created, one because if I open the index.php page it redirects me to the feed where it does its calcs, and two because I can see the cookie details in the settings in Chrome:
Name: TzSelect
Content: myvalue
Domain: xasdas.sxasmze.com
Path: /
Send for: Any kind of connection
Accessible to script: Yes
Created: Thursday, August 21, 2014 7:20:12 PM
Expires: Wednesday, May 17, 2017 7:20:12 PM
BUT, my problem is, the cookie doesn't have the selected value from the drop down list, in which case, the feed.php page loads, but instead of doing calculations with the selected option it does default EST calculations. I've been able to successfully pass the chosen value from the form to the feed page and do the proper calculations, but whenever I try to store that information in a cookie so the user doesn't have to set the timezone every time, it fails. Any ideas?