Page 1 of 1

Simple code but get error. expert help me!!!

Posted: Tue Sep 18, 2007 9:36 am
by dekindia
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


my code is

Code: Select all

<html>
	<head>
		<title>Cookies</title>
	</head>
	<body>
				hello world
				<?php setcookie('test',10,time()+12);?>
	</body>
</html>
and my out put is

hello world
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\ho.php:7) in C:\wamp\www\ho.php on line 7

many people say that this's caused from white space but this code 's so simple.
any suggestion? thank you in advance.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Sep 18, 2007 9:41 am
by CoderGoblin
Think of everthing you sent prior to the command <?php setcookie('test',10,time()+12);?>. That is your problem. You need to organise your code in a different way.

Code: Select all

<?php setcookie('test',10,time()+12);?>
<html>
<head>
<title>Cookies</title>
</head>
<body>
hello world
</body>
</html>
would work.

You may want to look at Laying out php code for readability and maintenance..., a short piece I wrote about laying out code to avoid this sort of issue.

Posted: Tue Sep 18, 2007 10:40 pm
by dekindia
THx alot ,That works