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

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
dekindia
Forum Newbie
Posts: 3
Joined: Tue Sep 18, 2007 9:28 am

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

Post 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]
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
dekindia
Forum Newbie
Posts: 3
Joined: Tue Sep 18, 2007 9:28 am

Post by dekindia »

THx alot ,That works
Post Reply