nloding Posted February 17, 2007 Share Posted February 17, 2007 My baby cousin was just watching Sesame Street ... anyway! This isn't exclusively a PHP issue, but it's not entirely Javascript either, so I wasn't sure where to post this ... Basically, I have an Ajax intensive site. Most of the Ajax, while not just there for looks, isn't part of the main portion of the site, which is e-commerce (catalog, cart, checkout, etc.). Depending on the page, Ajax is required to navigate it. I have a non-Ajax/javascript version, but I'm not sure the best way to implement it. My first idea was to have PHP create a cookie with a variable in it to test whether javascript was enabled for the user ... but that's not something PHP can test, being server-side, so I was wondering if javascript itself could do it. I don't know how cookies work -- if PHP creates a cookie, can javascript access it? Therefore, if javascript is supposed to write something to cookie, and that isn't present, then PHP can know if javascript is disabled? Otherwise, I'm forced with using the <noscript> tags and putting a link on the homepage to the non-javascript version, correct? Any other suggestions? PS: Still googling this question, but I can't find anything on javascript AND PHP using cookies, just one or the other ... Quote Link to comment Share on other sites More sharing options...
fert Posted February 17, 2007 Share Posted February 17, 2007 Javascript can create cookies and read cookies http://www.yourhtmlsource.com/javascript/cookies.html Quote Link to comment Share on other sites More sharing options...
nloding Posted February 17, 2007 Author Share Posted February 17, 2007 I know javascript can do that ... but I don't know how cookies work (sessions, cookies, and OOP are what I'm learning right now ). Is the cookie PHP creates for a site accessible by javascript, and vice versa? Or do they create different cookies? That was the short version of my long-winded question! Quote Link to comment Share on other sites More sharing options...
fert Posted February 17, 2007 Share Posted February 17, 2007 PHP can read cookies created by Javascript and vice versa Quote Link to comment Share on other sites More sharing options...
nloding Posted February 17, 2007 Author Share Posted February 17, 2007 That answers my question ... time to test! I'll consider this solved and open a new topic if something fails. Quote Link to comment Share on other sites More sharing options...
Nameless12 Posted February 17, 2007 Share Posted February 17, 2007 I don't know how cookies work -- if PHP creates a cookie, can javascript access it? cookies are just a bit of text that gets sent to your browser when it requests a page the web browser remembers this information and sends it back to the server with each request if it is valid the below is how it looks in header format in php you need to use header() to set the cookie using the below, but a lot of other languages allow you to type the headers by hand. after the two \n\n's are printed the headers are always sent. Php knows they have been sent for this reason and displays an error if you try to set more headers after they have been sent. Set-Cookie: key=value; [expires=DATE;] [path=PATH;] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.