Re: Cookie Trouble: getting the information back out...
| From: | Jim Lucas | Date: | Wed, 26 Mar 2008 04:16:02 +0000 |
| Subject: | Re: Cookie Trouble: getting the information back out... | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272105@lists.php.net to get a copy of this message | ||
Mark Weaver wrote:
Andrew Ballard wrote:The "problem" that you are encountering is because the $_COOKIE array is "populated" when the script is executed. More then likely the other languages that you used, would allow you to set a cookie and then they would enter them into the "global" array for you, and not make you wait until the next page load. You could accomplish this yourself by making a wrapper function for the setcookie() function and have your function set the data using setcookie() and having it enter the data directly into the $_COOKIE array. Something like this should do the trick <?php /* bool setcookie ( string $nameOn Tue, Mar 25, 2008 at 9:59 PM, Mark Weaver <mdw1982@mdw1982.com> wrote:Unless I was doing something differently when I originally wrote this in PERL I don't recall having this issue. At that time I would set the cookie and then redirect (load the index with the full menu) if cookie existed. Geez! now my $_SESSION isn't persisting to the next page when the screen refreshes. The only thing preventing me from gouging out my eyes right now is that I know I'll get this stuff. It's just a matter of time...Thank you Andrew... Now it all makes perfect sense. Good grief! there's so much to learn. It seems that Java was easier. ;)That's not specific to PHP. It's just how http works, so it's the same for ASP, Perl, I suspect Java and most (if not all) other languages. There might be a language that sets a cookie when you assign a value to a special cookie variable, but I'm not familiar with any. Andrew
[, string $value
[, int $expire
[, string $path
[, string $domain
[, bool $secure
[, bool $httponly ]]]]]] )
*/
function mySetCookie($name,
$value=null,
$expire=0,
$path='/',
$domain=null,
$secure=FALSE,
$httponly=FALSE) {
if ( is_null($domain) )
$domain = $_SERVER['SERVER_NAME'];
if ( setcookie( $name, $value, $expire,
$path, $domain, $secure, $httponly) ) {
$_COOKIE[$name] = $value;
return true;
}
return false;
}
?>