Page 1 of 1

cookies

Posted: Fri Jun 14, 2002 5:04 am
by opcd
hey,
I'm a newbie as you can see...
First of all I'd like to say i've read some topics about cookies and "read this before you post"...

I wanna use a cookie to see if a visitor has already been to my site... if so the requirementspage doesn't need to be loaded, neither does the enter button...
this is what I had

Code: Select all

<?php
	if ($_COOKIE &#1111;'opcdvisited'])
	&#123;
		$navigate = "flash.html";
		$req = "white.html";
	&#125;
	else
	&#123;
		setcookie ("opcdvisited", "opcd", time()+3600);
		$navigate = "enter.html";
		$req = "req.html";
	&#125;
?>
<html>
...
It works fine on my local server, but when i upload it, it gives following errors:
Notice: Undefined index: opcdvisited in d:\webroot\hosted\opcd\index.php on line 2

Warning: Cannot add header information - headers already sent by (output started at d:\webroot\hosted\opcd\index.php:2) in d:\webroot\hosted\opcd\index.php on line 9
the server (my host) uses php 4.21 and register_globals is turned off (so does my phpversion)

I know everything has to be send before any html tags so... ???
what's my problem?

Posted: Fri Jun 14, 2002 5:40 am
by twigletmac
Try,

Code: Select all

if (isset($_COOKIE &#1111;'opcdvisited']))
to test if the cookie has been set. The second error message is caused by the first error message being output to the browser.
Mac

Posted: Fri Jun 14, 2002 6:17 am
by opcd
k no errors anymore, but my cookie doesn't work...
the main cause was to see if a visitor had been here before (by checking if my cookie excists).. if so he doesn't need to see the requirements and enterpage, so normally it should load other pages... well it doesnt...

Code: Select all

<?php
	if (isset($_COOKIE &#1111;'opcdvisited']))
	&#123;
		$navigate = "flash.html";
		$req = "white.html";
	&#125;
	else
	&#123;
		setcookie ("opcdvisited", "opcd", time()+3600);
		$navigate = "enter.html";
		$req = "req.html";
	&#125;
?>
<html>
...

Posted: Fri Jun 14, 2002 7:52 am
by opcd
" cause " = purpose...

the script doesn't set my cookie, so it always runs the else structure...
is this a server thing? cause it works on my local... :(

Posted: Fri Jun 14, 2002 9:27 am
by hob_goblin

Code: Select all

<?php 
   if (isset($_COOKIE&#1111;'opcdvisited'])) 
   &#123; 
      $navigate = "flash.html"; 
      $req = "white.html"; 
   &#125; 
   else 
   &#123; 
      setcookie ("opcdvisited", "opcd",time()+3600)
        or die('Hmm, you have cookie issues');
      $navigate = "enter.html"; 
      $req = "req.html"; 
   &#125; 
?>
try that ;)

Posted: Fri Jun 14, 2002 10:31 am
by opcd
it works.. cant explain why, it's the same code...
but thanx :P

Posted: Fri Jun 14, 2002 2:18 pm
by opcd
there's another issue conserning my problem:
it works fine when I enter the direct adress in my adress bar
but when I use my redirect-adress it doesnt... huh???
it does load the same index.php file...