lAZLf Posted May 30, 2010 Share Posted May 30, 2010 I'm trying to show all the users cookies. So far I've tried: echo $HTTP_GET_VARS["cookie"]; and print_r($_COOKIE); In the first one, I don't get anything return, in the second i get "Array ( )". How do I do this? I want to write the user's cookies to a log. So in the long run I want it to be able to work in the fwrite() function. Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/ Share on other sites More sharing options...
Alex Posted May 30, 2010 Share Posted May 30, 2010 The second is correct. You just don't have any cookies set. Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065429 Share on other sites More sharing options...
jcbones Posted May 30, 2010 Share Posted May 30, 2010 $_COOKIE will return an empty array, if $_COOKIE is not set. if(!empty($_COOKIE)) { echo '<pre>'; print_r($_COOKIE); echo '</pre>'; } else { echo 'There are no Cookies, you must bake some.'; } Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065432 Share on other sites More sharing options...
lAZLf Posted May 30, 2010 Author Share Posted May 30, 2010 I ran that and it confirmed that i don't have any cookies set, but I'm logged into my admin account on my website (where that file is). Where does that search for the cookies? Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065435 Share on other sites More sharing options...
jcbones Posted May 30, 2010 Share Posted May 30, 2010 The users computer. Cookies are always on the end users computer. Unlike Sessions which is on your web server. Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065437 Share on other sites More sharing options...
lAZLf Posted May 30, 2010 Author Share Posted May 30, 2010 But there are many, many, many cookies on my computer, including the cookies used to log in on my website by checking the "remember me" tick, why aren't they showing up? Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065438 Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2010 Share Posted May 30, 2010 Cookies are domain specific. Also, depending on the subdomain/hostname and path settings in the cookie, cookies can also be specific to the subdomain/hostname and path where they were set. Only valid cookies (that have not expired), that match the domain, and optionally match the subdomain/hostname and path of the URL that is being requested will be sent to the server with the http request. Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065445 Share on other sites More sharing options...
lAZLf Posted May 30, 2010 Author Share Posted May 30, 2010 My code: <?php if(!empty($_COOKIE)) { $cookie = print_r($_COOKIE); } else { $cookie = 'There are no Cookies, you must bake some.'; echo $cookie; } $date = date("I ds of F Y h:i:s A"); $user_agent = $_SERVER['HTTP_USER_AGENT']; $file = fopen("log.txt", "a"); fwrite($file, "DATE : $date || USER AGENT : $user_agent || COOKIE : $cookie \n"); fclose($file); ?> So far, it only works with Firefox, not safari. In firefox it prints the cookies, but it writes into the log file "... COOKIE : 1". In safari it says that there are no cookies set, although there are. Anybody know why it writes COOKIE : 1 in the file in firefox, and nothing in safari? Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065452 Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2010 Share Posted May 30, 2010 print_r() only returns the data if you set the second parameter to TRUE. You do realize that each browser you have maintains separate cookies and would only supply its' cookies to the server with the http request. Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065457 Share on other sites More sharing options...
lAZLf Posted May 31, 2010 Author Share Posted May 31, 2010 Yes I do realize that, but could you elaborate on the http request? I've never been able to understand those Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065534 Share on other sites More sharing options...
PFMaBiSmAd Posted May 31, 2010 Share Posted May 31, 2010 http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol Quote Link to comment https://forums.phpfreaks.com/topic/203373-show-all-cookies/#findComment-1065538 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.