Results 1 to 4 of 4

Thread: Cookie problem

  1. #1
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Exclamation Cookie problem

    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:
    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/test.../ohp/index.php
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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....
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    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)
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •