Advice on PHP cookie problem

Associate
Joined
18 Oct 2002
Posts
2,055
Location
Southend-on-Sea
OK, bit of a newb with cookies, just trying to get my head round them but I can't seem to be able to get them to work.

Here is my code:

PHP:
<html>
	<head>
    <title>Cookies</title>
    </head>
    <body>
		<?php setcookie('test', 45, time()+(60*60*24*7)); ?>
	</body>
</html>

I'm getting the following error:

Warning: Cannot modify header information - headers already sent by (output started at C:\WEB\APACHE\htdocs\Archive\php_sandbox\cookies.php:6) in C:\WEB\APACHE\htdocs\Archive\php_sandbox\cookies.php on line 6

I've done a Google and whilst there seem to be lots of results, nothing seems to provide a solution.

Any ideas?

Thanks
 
Thanks Ringo.

So do you think I need to flush some info before setting the cookie? Not sure I understand that page info, do you know specifically which function I should be looking at?

Most of the Google responses seem to be about redundant white space in the code but I've tried several editors and there doesn't seem to be any white space.
 
Thanks PMWD, now sorted.

Its a bit weird though. I'm going through a lynda.com tutorial DVD and he has it the same as my original code and it seems to work for him.

Cheers anyway.
 
Back
Top Bottom