Log in

View Full Version : Cookie problem



fileserverdirect
08-22-2007, 08:01 PM
Hi, I recently had to change the name of my hompage document to index.php?w=y and that will dispaly the homepage. When you just go to index.php it detects the users window size and then re-directing you to index.php?w=y or index.php?w=n depending if its less than 860px wide. index.php is written in javascript, which then re-directs to the actual page. I have a command box,(where a user can enter in a command, like "PAY BILL" or "FORUMS" and it transfers it to the same page in which it was on. Then in an if command it dispalys "NOTE: Command Not reconized" or somthing. If it is forums lets say, then it will have "header(location:forums.php);" SO I decided to use cookies to set up the whole thing. It would only Detect the users screen size if the cookie wasn't set.
Here is the php Code:


$widthOdoc = $_GET['w'];
$window_size = $_COOKIE['window-size'];
//set cookies
if(!$window_size|| $widthOdoc)
{
setcookie('window-size', $widthOdoc);
$cookie_is_set = "yes";
}
else
{
$cookie_is_set = "no";
}
$window_size = $_COOKIE['window-size'];
//DOCUMENT START///////////////////////////////////////PART 04
//This is where I add a whole bunch of doctypes, metas, etc.
//DOCUMENT/////////////////////////////////////////////PART 05
//Find out what size the document is.
if(!$widthOdoc && $cookie_is_set=="no")
{
echo "<title>Please Wait...</title>\n</head>";
echo '<script type="text/javascript">
onload=function(){
var w = window.innerWidth? window.innerWidth : document.body.clientWidth? document.body.clientWidth : 640;
if(w>864)
window.location="index.php?w=y";
else
window.location="index.php?w=n";
}
</script>';
}
else
{
echo "DEBUG: Width O Doc: |$widthOdoc| COOKIE[Window- Size]: |$window_size| Is the Cookie set? |$cookie_is_set|";
//THE REST OF MY SITE IS HERE
}

NOTE:THE CODE ABOVE IS A SMALL SNIPPLET OF CODE WITH MANY OTHER LINES THAT WERE IRRELAVENT TO THE PROBLEM, WERE TAKKEN OUT.

Please Help, Why dosent it work? Here is a futher link to my site in testing:
http://www.klein-onlineblog.com/tests/PHP%20TESTS/ohp/index.php

djr33
08-22-2007, 08:38 PM
Using isset() on variables is a much better idea. It would make debugging easier, too.

Seems to work fine for me, using Firefox. Could it be a javascript problem with the browser you are using?

I don't see the problem on the page or in the code....

fileserverdirect
08-22-2007, 10:34 PM
Ok, the reason that this post is late is because I have worked all afternoon, and I worked out all of the 5 bugs in the script. djr33: You never looked at the debug line at the botom of the page, There were still errors. OK, I guess I can close this post. (Well I don't have the power to, but there is no reason to continue chatting, unless you have found a bug)

djr33
08-22-2007, 11:00 PM
I did see the debug line. Looks like it should work. But I didn't test it.
Anyway, glad it works.

I guess I'll lock it, though if you want it opened again, feel free to let me know.