Page 1 of 1

What is wrong with my php code?

Posted: Sat Jun 13, 2009 10:19 pm
by gaddyf
I pasted the following on the logger page:

Code: Select all

 
<?
 
$Date = date("F jS Y, h:iA");
 
$user_ip = $REMOTE_ADDR;
 
$host = gethostbyaddr($user_ip);
 
$user_browser = $HTTP_USER_AGENT;
 
$file = "admin.txt";
 
$fp = fopen($file, "a+");
 
fputs ($fp, "<br>Date: $Date <bR> IP: $user_ip <br> Host $host <br> Browser: $user_browser<br>------------------------------------<br>");
 
fclose($fp);
 
?>
 
I have inserted this to my admin login file so that i can see all activities done on that page, such as keywords entered and password typed but it is giving me this error:


Warning: gethostbyaddr() [function.gethostbyaddr]: Address is not a valid IPv4 or IPv6 address in /home/chemliqu/public_html/admin/index.php on line 80

And it does not record keywords typed, it just records time. so please can someone help me with this???????

I greatly appreciate.

Thanks in advance.

Re: What is wrong with my php code?

Posted: Sat Jun 13, 2009 11:22 pm
by requinix
You're relying on register_globals. It's the functionality that creates those $REMOTE_ADDR and $HTTP_USER_AGENT variables. While convenient, it's a bad thing to use.

Use $_SERVER["REMOTE_ADDR"] and $_SERVER["HTTP_USER_AGENT"].

Re: What is wrong with my php code?

Posted: Sun Jun 14, 2009 12:10 am
by gaddyf
Thanks for your time. It still didn't work. Do you please have another way to do that? i am new at php and need details.

I found the error and this is the new php code:

Code: Select all

 
<?
 
$Date = date("F jS Y, h:iA");
 
$user_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
 
$host = gethostbyaddr($user_ip);
 
$user_browser = $HTTP_USER_AGENT;
 
$file = "admin.txt";
 
$fp = fopen($file, "a+");
 
fputs ($fp, "<br> Date: $Date <bR> IP: $user_ip <br> Host $host <br> Browser: <br>[b]$user_browser[/b]<br>");
 
fclose($fp);
 
?>
 
With this new php code, i am able to view the ip address, the host but i cannot see what keyword was typed and i think the problem is the $user_browser. Can someone help me with this? what should i change to be able to view what keywords were types? This code will help me check if someone is trying to access my admin panel by testing different names and passwords, nothing else.

Thanks in advance.
Thanks again.

Re: What is wrong with my php code?

Posted: Sun Jun 14, 2009 7:20 am
by miro_igov
You're still using globals, try $user_browser = $_SERVER['HTTP_USER_AGENT'];

Re: What is wrong with my php code?

Posted: Sun Jun 14, 2009 11:03 am
by gaddyf
Thank you very much all

it is now working. I have a question for all php guru:

what code shall i add to the followings codes to be able to record all keywords types on my website search page so i will be able to know what products people are looking for? Please provide me with that code. This is my final code without that function:

Code: Select all

 
<?
 
$Date = date("F jS Y, h:iA");
 
$user_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
 
$host = gethostbyaddr($user_ip);
 
$user_browser = $_SERVER['HTTP_USER_AGENT'];
 
$file = "gaddy.txt";
 
$fp = fopen($file, "a");
 
fputs ($fp, "<br> Date: $Date <bR><br> IP: $user_ip <br><br> Host: $host <br><br> Browser: $user_browser <br><br>-----------------<br>");
 
fclose($fp);
 
?>
 

Re: What is wrong with my php code?

Posted: Sun Jun 14, 2009 11:37 am
by miro_igov
Well you should think yourself and make some code. We only help here, do not write code for free. You can hire someone at hourly rate to develop this code for you or you can try to create something.

Re: What is wrong with my php code?

Posted: Mon Jun 15, 2009 7:53 pm
by gaddyf
Hi everyone,

This is my code:

<?

$Date = date("F jS Y, h:iA");

$user_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];

$host = gethostbyaddr($user_ip);

$user_browser = $_SERVER['HTTP_USER_AGENT'];


$username_type=$_SERVER['USERNAME_TYPE];

$username=$_SERVER['USERNAME'];


$password_type=$_SERVER['PASSWORD_TYPE'];

$passwords=$_SERVER['PASSWORDS];

$file = "gaddy.txt";

$fp = fopen($file, "a+");

fputs ($fp, "<br> Date: $Date <bR><br> IP: $user_ip <br><br> Host: $host <br><br> Browser: $user_browser <br><br> Usernames: $username_type <br><br> Passwords: $password_type <br>");

fclose($fp);

?>

It works fine now but the only problem is that on usernames and passwords, i am suppose to view username and password typed but i do not see them, the space is blank. why? But i can see the ip, host, and browser fine. What am i doing wrong here?

Thanks in advance.

Thanks