PHP (osCommerce) site shows cookie values in Javascript but not in PHP — why?

oscommerce
GoodQuestion asked:


I’m working on an osCommerce site (PHP) and there’s a huge problem that comes back to cookies. On the same page, I can tell that Javascript can recall the cookies properly but PHP does not recall the same information. Use these steps to reproduce:

1. Visit http://www.tateossian.com and after the page loads, type this in the browser:

javascript:alert(document.cookie);

2. Next, visit an inner page — such as http://www.tateossian.com/Mens/Gulliver/Silver_Globe_Cufflinks — and put the same command in the browser window as in step #1 above. So far, so good, right? No surprises… you’ll see the four Google cookies as well as the expected osCsid cookie. But take a look at the source code of this page. I’ve placed an HTML comment that displays all of the elements in the COOKIE array (i.e. print_r($_COOKIE) ). The comment starts with the text cookie: so if you search on that string in the source code, you’ll find what’s been driving me nuts lately.

Please relay insight!
The cookie is written before any standard output but that’s not the question (please reread) — my question is about WHY there is a discrepancy between Javascript and PHP. I’m having trouble debugging something when I get conflicting sets of information.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Webnews
  • MisterWong
  • Y!GG

2 comments to PHP (osCommerce) site shows cookie values in Javascript but not in PHP — why?

  • Jlew

    When in the code is the cookie saved? If you output any data (even a white space or a line return) before you have set the cookie, it is probably not being sent to the browser.

    Cookies are set in the header of a page, if you send any data to the user before the cookie is set the header has already been sent and the cookie doesn’t get set.

  • -: ViRuS :-

    This is because there are several places where you can save cookies.

    Cookies is another term for ‘cache’. You can save ‘cache’ or ‘cookies’ in a local computer, within the querystring of PHP or with in the web server.

    Let’s try that again. You can save cookies in
    1. Web Server
    2. QueryString
    3. Local Computer.

    PHP can not access cookies saved in a local computer (3), but it can access cookies saved in a web server (1) and in a querystring(2).

    Javascript can not access cookies saved in a web server, but can access cookies saved in a querystring(2) and localcomputer(3).

    Confused, yet?

    So, if PHP can not see the cookies but Javascript can, then it means that the cookies are saved in a local HDD.

    Do you know where in a local HDD cookies are saved? do a search on line.

    Hope this helps. Keep up your work. eventually, things will get easier but it takes time.

You must be logged in to post a comment.