What is wrong with my php code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaddyf
Forum Newbie
Posts: 14
Joined: Sat Jun 13, 2009 10:09 pm

What is wrong with my php code?

Post 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.
Last edited by Weirdan on Sun Jun 14, 2009 11:06 am, edited 1 time in total.
Reason: added [code=php] tags
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: What is wrong with my php code?

Post 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"].
gaddyf
Forum Newbie
Posts: 14
Joined: Sat Jun 13, 2009 10:09 pm

Re: What is wrong with my php code?

Post 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.
Last edited by Weirdan on Sun Jun 14, 2009 11:06 am, edited 1 time in total.
Reason: added [code=php] tags
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: What is wrong with my php code?

Post by miro_igov »

You're still using globals, try $user_browser = $_SERVER['HTTP_USER_AGENT'];
gaddyf
Forum Newbie
Posts: 14
Joined: Sat Jun 13, 2009 10:09 pm

Re: What is wrong with my php code?

Post 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);
 
?>
 
Last edited by Weirdan on Sun Jun 14, 2009 11:07 am, edited 1 time in total.
Reason: added [code=php] tags
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: What is wrong with my php code?

Post 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.
gaddyf
Forum Newbie
Posts: 14
Joined: Sat Jun 13, 2009 10:09 pm

Re: What is wrong with my php code?

Post 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
Post Reply