/    Sign up×
Community /Pin to ProfileBookmark

Problem with cookies

Hello!
I have this problem: when user clicks on link it needs create cookie with parameter “1”, which will “live” 1 hour, but i get only this error: Warning: Cannot modify header information – headers already sent by (output started at Z:homelocalhostwwwphpsge-sltpldefaultindex.php:37) in Z:homelocalhostwwwphpsge-sltpldefaultindex.php on line 44
How can be this problem solved?

[code]<?
if(isset($_GET[‘id’])){
connect();
$a = mysql_query(“select * from servers WHERE id =”.$_GET[‘id’].””);
while($up = mysql_fetch_array($a, MYSQL_ASSOC) ){$upd = $up[rank] + 1; }
mysql_query(“UPDATE servers SET `rank` = “.$upd.” WHERE `id` ='”.$_GET[‘id’].”‘”);
SetCookie(“phpSGE-SL-Vote”,”1″);
header(‘location: ./’.$PHP[‘SELF’].”);
}
?>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
<title>{Title}</title>
<meta name=”keywords” content=”” />
<meta name=”description” content=”” />
<link href=”./tpl/default/default.css” rel=”stylesheet” type=”text/css” />
</head>
<body>
<div id=”outer”>
<div id=”header”>
<h1><a href=”#”>{SiteName}</a></h1>
<h2>{SiteDesc}</h2>
</div>
<div id=”menu”>
<ul>
<li class=”first”><a href=”#” accesskey=”1″ title=””>Home</a></li>
<li><a href=”./addserver.php” accesskey=”2″ title=””>Add Server</a></li>
</ul>
</div>
<div id=”content”>
<div id=”xbg1″></div>
<div id=”primaryContentContainer”>
<div id=”primaryContent”>
<h2>Last Servers</h2>
<table>
<?
connect();
$q = mysql_query(“select * from servers”);
(!$q) ? die(‘ERROR #1! ‘) :”;
while($r = mysql_fetch_array($q, MYSQL_ASSOC) ) {
echo ‘
<tr class=”rowA”><td>’.$r[rank].”;
if (SetCookie(“phpSGE-SL-Vote”,”1″)){
echo “”;
}else{
echo ‘<a href=”?id=’.$r[id].'”>[+1]</a>’;
}
echo ‘</td><td>’.$r[name].'</td><td><a href=”‘.$r[link].'”>Connect!</a></td></tr>’;
}
?>
</table>
</div>
</div>
<div id=”secondaryContent”>
<h3>Menu</h3>
<p><a href=”./index.php”>Home</a><br />
<a href=”./addserver.php”>Add Server</a><br />
<a href=”http://amxdm-fortes.tk/phpsge-gl”>phpSGE GL page</p>
<h3>Text</h3>
<p>Sed eu eros imperdiet eros interdum blandit. Vivamus sagittis bibendum erat. Curabitur malesuada. <a href=”#”>More…</a></p>
<h3>Text</h3>
<p>Sed vestibulum blandit nisl. Quisque elementum convallis purus. Suspendisse potenti. Donec nulla est, laoreet quis, pellentesque in. <a href=”#”>More…</a></p>
<h3>Text</h3>
<ul>
<li><a href=”#”>Sagittis Bibendum Erat</a></li>
<li><a href=”#”>Malesuada Turpis</a></li>
<li><a href=”#”>Quis Gravida Massa</a></li>
<li><a href=”#”>Inerat Viverra Ornare</a></li>
</ul>
</div>
<div class=”clear”></div>
</div>
<div id=”footer”>
<p>Copyright &copy; {Year} {Title}<br />
Powered by <a href=”http://amxdm-fortes.tk/phpsge-sl”>phpSGE SL</a> Project. Coded by <a href=”http://www.amxdm-fortes.tk”>Nikita [Fortes] Kushnir</a>. Designed by <a href=”http://www.freecsstemplates.org”>Free CSS Templates</a></p>
</div>
</div>
</body>
</html>[/code]

pS: Sorry for my bad English.
Nikita

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@007JulienDec 04.2011 — From php.net manual

[B]setcookie()[/B] defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace.
×

Success!

Help @AgManiX 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 4.28,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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