With a good start from the folks on this list and a little JavaScript
digging, I found an excellent solution to my problem that I thought I'd share:

Problem: Want to set a cookie then test for it on the same page.  I don't
want to to do page redirection to ensure optimal search engine friendliness.

Solution: Set the cookie in PHP then test for the cookie with JavaScript.
Code example below:

if (! $MySession)
        $SessionID = "2001 A Space Odyssey";
< h t m l > <!--html tag done that way to ensure non-HTML appearance in e-mail
<title>Test Page</title>

cookie_name = "MySession";
var Session;

function getSession()
                index = document.cookie.indexOf(cookie_name);
                if (index != -1)
                        namestart = (document.cookie.indexOf("=", index) + 1);
                        nameend = document.cookie.indexOf(";", index);
                        if (nameend == -1)
                                nameend = document.cookie.length;
                        Session = document.cookie.substring(namestart, nameend);
                        return Session;

if (!Session)
        CookieMessage = "Cookies are not enabled.  You can browse the site, but
will need to enable them to be able make a purchase."
        CookieMessage = ""
<SCRIPT LANGUAGE="javascript">

blah, blah, blah, the rest of the web page...

Jeff Gannaway

At 03:36 PM 7/5/01 -0500, Jeff Gannaway wrote:
>OK, I'm working on a site that absolutely must use a cookie containing a
>session identifier.
>I know how to set a cookie through PHP, but I need to do something else too.
>The same page MUST identifier whether the cookie was accepted or not.  I've
>seen sites like NetFlix.com that will test to see if their cookie was
>accepted, and if not, print up a page that says "Sorry, you've got have
>your Cookies on or go somewhere else."
>Jeff Gannaway

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to