|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-03-11 14:47 UTC] mail at sethknorr dot com
print_r($_COOKIE);
Does not print Session cookies. IE from another global source.
example in Perl if you use the variable it shows all cookies including session ones:
$ENV{'HTTP_COOKIE'}
print_r($_COOKIE);
Will show the same variables as $ENV{'HTTP_COOKIE'} minus any session cookies. I looked through this site but saw no documentation on this and am thinking it is posibly a bug in PHP.
Thanks for your attention to this.
Seth Knorr
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 06 11:00:02 2025 UTC |
What I mean by session cookie is one that is set but then deleted once you would leave that web site. Example If I where to use the Perl code below to set a cookie, it would be read in perl with the variable $ENV{'HTTP_COOKIE'} but not with print_r($_COOKIE); ################# #Start Perl Code ################# $user = "test"; $pass = "pass"; $cookie = &SetCookie("susername", $user, 0); print $cookie; $cookie = &SetCookie("spassword", $pass, 0); print $cookie; sub SetCookie() { my ($name,$value,$expires,$path,$domain) = @_; $name=&CookieRE($name); $value=&CookieRE($value); $expires=$expires * 24 * 60 * 60; my $expire_at=&CookieDate($expires); my $namevalue="$name=$value"; my $COOKIE=""; if ($expires != 0) { $COOKIE= "Set-Cookie: $namevalue; expires=$expire_at; "; } else { $COOKIE= "Set-Cookie: $namevalue; "; } if ($path ne ""){ $COOKIE .= "path=$path; "; } if ($domain ne ""){ $COOKIE .= "domain=$domain; "; } $COOKIE .= "\n"; return $COOKIE; } sub CookieDate() { my ($seconds) = @_; my %mn = ('Jan','01', 'Feb','02', 'Mar','03', 'Apr','04', 'May','05', 'Jun','06', 'Jul','07', 'Aug','08', 'Sep','09', 'Oct','10', 'Nov','11', 'Dec','12' ); my $sydate=gmtime(time+$seconds); my ($day, $month, $num, $time, $year) = split(/\s+/,$sydate); my $zl=length($num); if ($zl == 1) { $num = "0$num"; } my $retdate="$day $num-$month-$year $time GMT"; return $retdate; } sub CookieRE() { my($retval) = @_; $retval=~s/\;//; $retval=~s/\=//; return $retval; } ################# #End Perl Code ################# Where as for example if I used this java script code to set cookies, will apear in both the $ENV{'HTTP_COOKIE'} and with print_r($_COOKIE); <SCRIPT LANGUAGE = "JavaScript"> <!-- function setCookie(name, value, expires) { document.cookie = name + "=" + escape(value) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString()); } function getValue(element) { var value = getCookie(element.name); if (value != null) element.value = value; } function setValue(element) { setCookie(element.name, element.value, exp); } var exp = new Date(); exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31)); function delCookie(name) { document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/"; } //--> </SCRIPT> <form OnSubmit = "setValue(document.form.username) + setValue(document.form.password);"> Etc... Hopefully that maks sense, I know the last thing you want to do is read perl code but it will give you an example of what I mean. Seth