Re: Cookie Trouble: getting the information back out...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mark Weaver wrote:
Andrew Ballard wrote:
On Tue, Mar 25, 2008 at 9:59 PM, Mark Weaver <mdw1982@xxxxxxxxxxx> wrote:
 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


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...


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 $name
              [, 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;
}


?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux