/    Sign up×
Community /Pin to ProfileBookmark

Well I am having problems getting values of the cookies i am setting
This is how i am creating it

[code=php]$value= “UID, UN”;
$expire = time()+60*60*24*30;
$path = “/”;
$domain= “.example.com”;
$secure = false;
$httponly = true;
$Test = setcookie(“Test”, $value, $expire, $path, $domain, $secure, $httponly);[/code]

but i dont know how to get the values

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJan 19.2009 — The values are available in the $_COOKIE superglobal. So in your example, you should be able to access the value via $_COOKIE['Test'].
Copy linkTweet thisAlerts:
@moiseszaragozaauthorJan 19.2009 — Ok here is what i have but i am still having the problem

[code=php]

$value= "UID, UN";
$expire = time()+60*60*24*30;
$path = "/";
$domain= ".example.com";
$secure = false;
$httponly = true;
$Test = setcookie("Test", $value, $expire, $path, $domain, $secure, $httponly);
if (!isset($_COOKIE['bizLogin'])){


echo 'Hello ' . htmlspecialchars($_COOKIE["Test"]) . '!'; // Hello !




}else{
echo("cookie is NOT set");
}


[/code]


but i am still not getting a value
Copy linkTweet thisAlerts:
@MindzaiJan 19.2009 — But you're setting a cookie called 'Test', then checking for a cookie called 'bizLogin'.

To easily see what cookies are set, just add the following:

[code=php]
echo '<pre>';
print_r($_COOKIE);
echo '</pre>';
[/code]
Copy linkTweet thisAlerts:
@moiseszaragozaauthorJan 19.2009 — Thanks

I got something back but i am not sure what it is.

i changed my code to look like

[code=php]


<?php
$value= "UID, UN";
$expire = time()+60*60*24*30;
$path = "/";
$domain= ".example.com";
$secure = false;
$httponly = true;
$Test = setcookie("Test", $value, $expire, $path, $domain, $secure, $httponly);
if (!isset($_COOKIE['bizLogin'])){


//echo 'Hello ' . htmlspecialchars($_COOKIE["Test"]) . '!';


echo '<pre>';
print_r($_COOKIE);
echo '</pre>';


}else{
echo("cookie is NOT set");
}


?>

[/code]



and i got back

[CODE]

Array
(
[__utma] => 60536766.2291088238559418000.1232376989.1232376989.1232376989.1
[__utmb] => 60536766.18.10.1232376989
[__utmc] => 60536766
[__utmz] => 60536766.1232376989.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
[PHPSESSID] => s5t5d704jvik9fpfo2m6g4l132
)



[/CODE]
Copy linkTweet thisAlerts:
@MindzaiJan 19.2009 — Try this:

[code=php]
<?php
$value= "UID, UN";
$expire = time()+60*60*24*30;
$path = "/";
$test = setcookie("Test", $value, $expire, $path);

echo '<pre>';
print_r($_COOKIE);
echo '</pre>';
?>
[/code]


It's probably because you're setting the domain to example.com and i'm guessing that isnt the domain you're testing on.
Copy linkTweet thisAlerts:
@moiseszaragozaauthorJan 19.2009 — i am not sure as i am still getting

Array

(

[__utma] => 60536766.2291088238559418000.1232376989.1232376989.1232379589.2

[__
utmz] => 60536766.1232376989.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)

)


back
Copy linkTweet thisAlerts:
@moiseszaragozaauthorJan 19.2009 — But thanks again.

I set my domain and it works perfectly
×

Success!

Help @moiseszaragoza 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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