|
-
Jan 28th, 2007, 09:11 AM
#1
Thread Starter
Frenzied Member
Cookie code, whats wrong?
whats wrong with my cookie code? I am pretty sure my code SHOULD work 100%, yet it doesn't.....
Code:
<?php
if ( $_GET["RSN"] == "" || $_GET["RSN"] == "null")
{
$username = $_COOKIE["TipMeName"];
//echo '<script type="text/javascript">alert("Getting An Allready Set Cookie: '.$_COOKIE["TipMeName"].'")</script>';
} else {
setcookie("TipMeName", $_GET["RSN"] , time()+5184000 );
header( 'refresh: 0; url=/1/' );
//echo'<script type="text/javascript">alert("Setting A New Cookie: '.$_COOKIE["TipMeName"].' - '.$_GET["RSN"].'")</script>';
}
if (isset($_COOKIE["TipMeName"]))
{
echo
'
<fieldset>
<table border="0" width="100%">
<tr>
<td>
<p align="center"><font size="2">Your RS Name Is:"' .$username. '"</font><br>
<form action="#" method="get">
RSN:
<input type="text" name="RSN" size="20">
<input type="submit" value="Change It">
</form>
</p>
</td>
</tr>
</table>
</fieldset>
';
} else {
echo
'
<fieldset>
<table border="0" width="100%">
<tr>
<td>
<p align="center"><font size="2">---text goes here the i removed--
tools.</font></td>
</tr>
<tr>
<td>
<p align="center"><b><font size="2" color="#FF0000">No RS Username is set!</font></b><br>
<form action="#" method="get">
RSN:
<input type="text" name="RSN" size="20">
<input type="submit" value="Save Name">
</form>
</p>
</td>
</tr>
</table>
</fieldset>
';
}
?>
Last edited by wiz126; Jan 28th, 2007 at 12:10 PM.
-
Jan 28th, 2007, 11:16 AM
#2
Re: Cookie code, whats wrong?
Cookies you just set aren't immediately available in the _COOKIES superglobal, only after the next browser request.
Or is your problem different? If so, tell us what it is.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 28th, 2007, 12:12 PM
#3
Thread Starter
Frenzied Member
Re: Cookie code, whats wrong?
 Originally Posted by CornedBee
Cookies you just set aren't immediately available in the _COOKIES superglobal, only after the next browser request.
Or is your problem different? If so, tell us what it is.
that is correct, and thats why I placed this code:
Code:
header( 'refresh: 0; url=/1/' );
I just realized that my code works perfectly fine when its on a page of its own. but once I copy and past it into my main page. it stops working....
-
Jan 28th, 2007, 01:14 PM
#4
Re: Cookie code, whats wrong?
did you send any output before executing that code?
once you send output to the browser, cookie and header functions cannot be executed.
Last edited by kows; Jan 28th, 2007 at 01:24 PM.
-
Jan 28th, 2007, 03:10 PM
#5
Thread Starter
Frenzied Member
Re: Cookie code, whats wrong?
 Originally Posted by kows
did you send any output before executing that code?
once you send output to the browser, cookie and header functions cannot be executed.
Can you explain a bit more?
-
Jan 28th, 2007, 05:13 PM
#6
Re: Cookie code, whats wrong?
setcookie() adds a "Set-Cookie" header to the set of headers sent to the browser. Headers must always be sent before the page content; that's a HTTP requirement.
When PHP first encounters normal content, unless content buffering is on, it sends the headers and starts the content output. Thus, after any normal content was encountered, the setcookie() function has no effect anymore.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 28th, 2007, 06:34 PM
#7
Thread Starter
Frenzied Member
Re: Cookie code, whats wrong?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|