...

View Full Version : Unusual result...



SDP2006
10-29-2003, 01:21 AM
I am using this script
<?php
$add = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$thefile = fopen("ipgrabber.txt","a+");
fwrite($thefile, $add . " -- " . $agent . "\n\n\n\n\n\n");
fclose($thefile);
?>To write the IP Address and Browser of my visitors to a file. For some reason, it is writing the IP Address -- and my PHP Version! 4.2.3

Why is this?

Acecool
10-29-2003, 03:44 PM
The code should work, theres nothing to do with the php version, check if theres another fopen with the same txt somewhere or if agent / the other is getting .= with the php version

SDP2006
10-29-2003, 07:00 PM
Oh, but it is -- http://www.net-riches.com/php-bin/ipgrabber.txt

SDP2006
10-30-2003, 02:43 AM
Does anyone know what my scripting problem is?

ConfusedOfLife
10-30-2003, 05:22 PM
Did you print out $_SERVER["HTTP_USER_AGENT"] b4 writing it into the file?? Does it show what you expect?? If yes, then try to fopen the file by "w" switch, check if you see any differences. You should play with it a little bit, you know! It's always the same

SDP2006
10-30-2003, 08:55 PM
Changed it to fopen($file, "w") and it still is writing the PHP version

mordred
10-30-2003, 11:57 PM
How exacly did you embed/call the script?

There is a php.ini setting called user_agent which contains a string PHP uses as user agent for HTTP requests. If you include your ipgrabber like



include 'http://domain/ipgrabber.php';


you send a request and PHP will turn up as user agent, not the user agent of the browser which requested the original page. See also this bug description, though it is for fopen(): http://bugs.php.net/bug.php?id=23256

If that's the problem, you can solve it quite easily by changing the absolute URL to a relative one.

SDP2006
10-31-2003, 12:30 AM
I call it in my index.php like this
<?php include('http://www.net-riches.com/php-bin/ipgrabme.php'); ?>

mordred
10-31-2003, 12:37 AM
Well, then the result you get is not at all unusual, everything works as expected. How to 'fix' this is written in detail in my post above. ;)

SDP2006
10-31-2003, 12:38 AM
I've tried to do that


<?php
include('../php-bin/ipgrabber.php');
?>
and I get some open_base_dir() error

mordred
10-31-2003, 10:15 AM
And the path is correct? Then your server is misconfigured. Ask your host to fix that by allowing you access to your subdirectories.

Acecool
10-31-2003, 12:42 PM
<?php
require("./includes/common.php");
require("./addons/ac_security.php");
$SaveThisToInfotxt = file_get_contents("./addons/info.txt");

$SaveThisToInfotxt .= "" . $_ACWB['HTTP_USER_OS'] . "//";
$SaveThisToInfotxt .= "" . $_ACWB['HTTP_USER_BROWSER'] . "//";
$SaveThisToInfotxt .= "" . $_ACWB['HTTP_USER_IP'] . "//";
$SaveThisToInfotxt .= "" . $_ACWB['HTTP_USER_HOST'] . "//";
$SaveThisToInfotxt .= "" . $_ACWB['HTTP_USER_PORT'] . "//";
$SaveThisToInfotxt .= "" . $_ACWB['HTTP_USER_REFERER'] . "//";
$SaveThisToInfotxt .= "" . $_ACWB['HTTP_USER_DATE'] . "////";
$SaveThisToInfotxt .= "Debugging (0)" . $_ACWB['HTTP_USER_AGENT_RETURN'][0] . "|(1)" . $_ACWB['HTTP_USER_AGENT_RETURN'][1] . "|(2)" . $_ACWB['HTTP_USER_AGENT_RETURN'][2] . "|(3)" . $_ACWB['HTTP_USER_AGENT_RETURN'][3] . "\n";

ac_EditFile("./addons/info.txt", $SaveThisToInfotxt);
?>

This shows up fine, the acwb ip is: $_ACWB['HTTP_USER_IP'] = $_SERVER['REMOTE_ADDR'];
$_ACWB['HTTP_USER_IP'] = $_SERVER['REMOTE_ADDR'];
$_ACWB['HTTP_USER_PORT'] = $_SERVER['REMOTE_PORT'];
$_ACWB['HTTP_USER_REFERER'] = $_SERVER['HTTP_REFERER'];
$_ACWB['HTTP_USER_HOST'] = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$_ACWB['HTTP_USER_DATE'] = date ("l dS F Y h:i:s A");


$_ACWB['HTTP_USER_AGENT_RETURN'] = explode(";" ,"" . $_SERVER['HTTP_USER_AGENT'] . "");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum