/    Sign up×
Community /Pin to ProfileBookmark

error with setting cookie

Hi there,

I have created the following codes:
<?php
$model = $_REQUEST[“model”];
$colour = $_
REQUEST[“colour”];
$quantity = $_REQUEST[“quantity”];
$cookieValue = “$model $colour”;
setcookie(“ProductView”, $cookieValue);
?>

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<title>MoWidgets.com</title>
<link rel=”stylesheet” href=”myStyle.css”>

</head>

…. on and on

But when run, the error msg is:
Warning: Cannot modify header information – headers already sent by (output started at C:XitamiwebpagesdisplayProduct.php:2) in C:XitamiwebpagesdisplayProduct.php on line 6

anyone can help?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsSep 27.2004 — if there is a character, newline, return, or any html before the code block containning the setcookie() function it will fail
Copy linkTweet thisAlerts:
@terry81authorSep 27.2004 — Hi there,

thanks. i realised you cant leave any spoacing or empty line in between.
Copy linkTweet thisAlerts:
@HellspireSep 27.2004 — That is NOT true.... if you put

ob_start(); at the beginning, and

ob_end_flush(); at the end (of the file)

Then you can call or set cookies, sessions, header calls etc without a problem....

Furthermore you are not including all the variables required for setcookie

setcookie("nameofcookie","valueofcookie","timetillexpires","directoryinwhichcookiehaseffect",".mysite.com");

there is one other arguement 0 or 1 for secure sites required before setting but youll most likely not need to set this unless your using https://

CHeers
Copy linkTweet thisAlerts:
@Paul_JrSep 27.2004 — [i]Originally posted by Hellspire [/i]

[B]Furthermore you are not including all the variables required for setcookie[/B][/QUOTE]

[font=palatino linotype]Actually, if you can believe it, the only required argument is the cookie name.[/font]
×

Success!

Help @terry81 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...