Page 1 of 1

Detecting cookie snippet...

Posted: Mon Feb 21, 2005 5:50 pm
by theda
I have yet another question...

I posted a thread earlier about how to use cookies to create a skinning system, and got all the help I needed here, and it works just fine. Now onto my next task: I'm wondering if there is a way to detect if a cookie is set in a persons PC, and if not, have the page automatically redirect them to a page that would allow them to set a cookie to view the page correctly.

My idea was

Code: Select all

if (cookie is set) &#123; <my sites script here> &#125; else &#123; <redirection code> &#125;
What I don't know is how to check for a cookie doing the way I want to do it.

Posted: Mon Feb 21, 2005 5:55 pm
by Burrito

Code: Select all

if(isset($_COOKIE&#1111;'whatever']))&#123;
$redirect = 0;
&#125;else&#123;
$redirect = 1;
&#125;

Posted: Mon Feb 21, 2005 6:19 pm
by theda
Now when you have redirect = 0... and then redirect = 1... How is that actually going to redirect?

I've seen the "header("Location: ADDRESS");" thing... Im wondering if that'd work instead of redirect = 1/0.

Posted: Mon Feb 21, 2005 6:22 pm
by feyd
do the redirect in the code block appropriate to the action you wish to take.

I believe the 'else' is where you want it.

Posted: Mon Feb 21, 2005 6:32 pm
by theda
What do you mean by that?

This is what I did:

Code: Select all

//Cookie check
if(isset($_COOKIE&#1111;'language']))&#123;
header("location: blah");
&#125;else&#123;
include($ver.".content.php");
&#125;
and all I get is "header error, already loaded..."

edit: the reason the header is already sent is because in my set.php page it uses headers to redirect.

edit 2: I'll look through my script to see if I can move things around to remove this error.

edit 3: I moved things around and it doesn't cause the error anymore, but instead of redirecting if it doesnt detect the cookie, it just... loads everything I told it not to load unless there is a cookie...anyway.

last edit: I moved things around and figured out what the problem is. I got everything working right. Thanks for the help.

PHENOM | PLEASE USE

Code: Select all

TAGS WHILE

Code: Select all

TAGS ARE OFFLINE[/color]