Determine client cookie support via initial headers?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Determine client cookie support via initial headers?

Post by JAB Creations »

When a browser makes it's initial request is there any way to determine through the headers sent by the browser if cookies are enabled?

For clarification a desirable time line...
1.) Client sends request with browser's headers.
2.) PHP needs to determine if client supports cookies.
3.) PHP either creates cookies and sends client an error message telling them to enable cookies.

If the client does not support cookies on the initial hit I need to make them aware before they make a second request. That is my goal.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Determine client cookie support via initial headers?

Post by Benjamin »

I'm fairly certain you'll have to attempt to set a cookie then immediately redirect to a page that will test that the cookie was set, then either redirect to the destination or an error page.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Determine client cookie support via initial headers?

Post by JAB Creations »

Using header in PHP is there a simple "reload/refresh" command I could use in conjunction with the header command to achieve this?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Determine client cookie support via initial headers?

Post by Benjamin »

User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Determine client cookie support via initial headers?

Post by JAB Creations »

How can we refresh the page using the following code and add an HTTP query.

Code: Select all

if (!isset($_COOKIE['counter'])) {header('Refresh: 1;');}
I'd like to add an http query such as ?cookie=0 or ?cookie=1 depending on if cookies are detected for the purpose of statistical analysis.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Determine client cookie support via initial headers?

Post by Benjamin »

It would look more like:

Code: Select all

 
if (!isset($_COOKIE['counter']))
{
    header('Location: http://domain.com/page.php?cookie=0');
} else {
    header('Location: http://domain.com/page.php?cookie=1');
}
 
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Determine client cookie support via initial headers?

Post by JAB Creations »

I know how to do that, I don't know the dynamic command for this-url, regardless of what it is. This PHP script needs to be dynamically used by multiple files where file names may constantly be changing.
Post Reply