I'm having a bit of an issue here.
I'm writing some PHP (with Javascript) to display certain css elements as a large size, or a small size, depending on the display width of the computer.
As it goes now:
No cookie or session information with regards to display width -> load javascript that detects screen width -> redirect to URL with variable that will allow for the creation of cookies and sessions -> redirect back to clean URL with properly sized element.
It works fine with cookies. However, with sessions I'm getting an infinite loop.
10 set session using URL with variables
20 redirect to clean URL
30 goto 10
This is baffling me. I'm missing something. If I turn on error reporting (E_ALL), I get no relevant errors, and thankfully a few "undefined index:" errors will stop the loop and allow me to see that the session is taking properly. So, what gives?
I'd just like to add... WHY oh WHY isn't there a predefined variable for screen size in PHP?
**EDIT: I could be wrong about the session being set properly. In subsequent tests, it looks like it's NOT taking.**
**EDIT #2: It would appear that calling a redirect of any sort, be it through header(location:) in PHP or window.location in Javascript, seems to bork the session information. Does anyone know why this would happen?
I'm writing some PHP (with Javascript) to display certain css elements as a large size, or a small size, depending on the display width of the computer.
As it goes now:
No cookie or session information with regards to display width -> load javascript that detects screen width -> redirect to URL with variable that will allow for the creation of cookies and sessions -> redirect back to clean URL with properly sized element.
It works fine with cookies. However, with sessions I'm getting an infinite loop.
10 set session using URL with variables
20 redirect to clean URL
30 goto 10
<?php
session_start();
if (($_GET["screensize"]) && (!isset($_SESSION['menusize'])) && (!isset($_COOKIE["w_menusize"])))
{
$twoyears = 60 * 60 * 24 * 730 + time();
if ($_GET["screensize"] == "small")
{
if(!setcookie('w_menusize', "small", $twoyears, "/"))
{
$_SESSION['menusize'] = "small";
}
header("location: http://www.myurl.com");
}
else
{
if(!setcookie('w_menusize', "large", $twoyears, "/"))
{
$_SESSION['menusize'] = "large";
}
header("location: http://www.myurl.com");
}
}
===
echo "<html>\r\n";
echo "\t<head>\r\n";
if ((!isset($_COOKIE["w_menusize"])) && (!isset($_SESSION['menusize'])) && (!$_GET["screensize"]))
{
echo "\t\t<script type=\"text/javascript\">\r\n";
echo "<!--\r\n";
echo "\t\t\tvar screenwidth = screen.width;\r\n";
echo "\t\t\tif (screenwidth <= 1124)\r\n";
echo "\t\t\twindow.location=\"http://www.myurl.com?screensize=small\"\r\n";
echo "\t\t\telse\r\n";
echo "\t\t\twindow.location=\"http://www.myurl.com?screensize=large\";\r\n";
echo "-->\r\n";
echo "\t\t</script>\r\n";
}
echo "\t</head>\r\n";
if (($_COOKIE["w_menusize"] == "small") || ($_SESSION['menusize'] == "small"))
{
$xscreensize = "small";
// Changes the name of CSS element, adding "small" to the end of the name
}
else
{
$xscreensize = "";
}
echo "<a href=\"http://www.myurl.com/blog/\" title=\"Blog\"><img src=\"http://www.myurl.com/img/blank.gif\" alt=\"Blog\" id=\"blogrollover" . $xscreensize . "\" /></a>";
</html>
?>
This is baffling me. I'm missing something. If I turn on error reporting (E_ALL), I get no relevant errors, and thankfully a few "undefined index:" errors will stop the loop and allow me to see that the session is taking properly. So, what gives?
I'd just like to add... WHY oh WHY isn't there a predefined variable for screen size in PHP?
**EDIT: I could be wrong about the session being set properly. In subsequent tests, it looks like it's NOT taking.**
**EDIT #2: It would appear that calling a redirect of any sort, be it through header(location:) in PHP or window.location in Javascript, seems to bork the session information. Does anyone know why this would happen?
