Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting cookies inside functions

Status
Not open for further replies.

andnos

Technical User
Nov 21, 2005
48
US
This might a weird question, but I'm able to set cookies OUTSIDE of a function, but not inside of a function. maybe somebody has come across this before. I'm using PHP 5.2.1 Here's the code that I have, the utoutside coookie sets fine, the utinside cookie DOES not set, I've never seen this before, any ideas on how to remedy this?

$domainName = "example.com";
function MyCookie()
{
global $_COOKIE, $GLOBALS;
setcookie('utinside','inside',2147483647,'/','.'.$domainName.'');
return true;
}

MyCookie();
setcookie('utoutside','outside',2147483647,'/','.'.$domainName.'');
 
I've tried with the global variables and without, it didn't change anything.

 
You're probably using the [tt]global[/tt] operator on the wrong variables.

DON'T use it on $_COOKIE or $GLOBALS, as they are superglobals and thus available in every variable namespace.

DO use it on $domainName, otherwise the right one won't be available in the function.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Dude, you rock man!!!!!!!!!
it's stuff like this that sends me on a two hour chase.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top