cookies

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
opcd
Forum Newbie
Posts: 12
Joined: Mon Jun 03, 2002 12:54 pm

cookies

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
opcd
Forum Newbie
Posts: 12
Joined: Mon Jun 03, 2002 12:54 pm

Post 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>
...
opcd
Forum Newbie
Posts: 12
Joined: Mon Jun 03, 2002 12:54 pm

Post 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... :(
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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 ;)
opcd
Forum Newbie
Posts: 12
Joined: Mon Jun 03, 2002 12:54 pm

Post by opcd »

it works.. cant explain why, it's the same code...
but thanx :P
opcd
Forum Newbie
Posts: 12
Joined: Mon Jun 03, 2002 12:54 pm

Post 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...
Post Reply