•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 361,854 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,630 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2018 | Replies: 12
![]() |
Hello, Im trying To create A code In php That Does the Following:
A. detects visiting users real ip address
B. detects city and country
C. detects browser type and version
D. detects referrer url
E. detects landing page
F. appends this information to a txt file
Im using the following php file hosted in same folder as the txt file, and using
in my html.
txt file
php
Im getting odd results as all entrys show same ip . please help?
This cant all be same user as Ive been watching. Ip showing for all entries
Please help me do What Im trying to.
A. detects visiting users real ip address
B. detects city and country
C. detects browser type and version
D. detects referrer url
E. detects landing page
F. appends this information to a txt file
Im using the following php file hosted in same folder as the txt file, and using
<script src='http://h1.ripway.com/Inny/spy/spy.php'></script>
in my html.
txt file
<html> <head> <title>Spy</title> <body background="http://i14.photobucket.com/albums/a345/Instar/escher_background.gif"> </head> <body> <SCRIPT src='http://h1.ripway.com/Inny/spy/pass.js'></SCRIPT> <center><font color='red'> <form method="POST" action="http://www.geobytes.com/IpLocator.htm?GetLocation"> <input type="hidden" name="cid" value="0"> <input type="hidden" name="c" value="0"> <input type="hidden" name="Template" value="iplocator.htm"> <h3>IP Address to locate:<input type="text" name="ipaddress" size="15" value=""> <input type="submit" value="Submit"> </h3> </form> </center>
php
<html>
<head>
<title>Spy</title>
</head>
<body background="http://i14.photobucket.com/albums/a345/Instar/escher_background.gif">
<center><h2>
<center>
<table border="5" bg color="white">
<tr>
<td><center>
<body>
<?php
$spy = fopen("spy.html" , "a");
$site = $HTTP_REFERER;
$ip = $REMOTE_ADDR;
$browser = $HTTP_USER_AGENT;
$time = date("H:i dS F");
echo "<font color='red'>The site User came from: " . $_SERVER["HTTP_REFERER"] . "<br />";
echo "<font color='blue'>ALL IP ADRESSES, TIME, SITE AND USERS BROWSERS ARE BEING CAPTURED!";
fwrite($spy,"<font color='blue'><<<<<------------BEGIN------------>>>>></font><br />");
fwrite($spy,"<font color='black'>Site user came from: $site <br />");
fwrite($spy,"IP Address: $ip <br />");
fwrite($spy,"Browser: $browser <br />");
fwrite($spy,"Time: $time <br />");
fwrite($spy,"<font color='red'><<<<<------------END------------>>>>></font><p/><p>");
fclose($spy);
?>
</table>
</center></td>
</tr>
</table border>
</body>
</html>Im getting odd results as all entrys show same ip . please help?
•
•
•
•
<<<<<------------BEGIN------------>>>>>
Site user came from: http://herproom.5.forumer.com/index.php?
IP Address: 192.168.0.5
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)
Time: 00:11 26th November
<<<<<------------END------------>>>>>
<<<<<------------BEGIN------------>>>>>
Site user came from: http://herproom.5.forumer.com/index.php?
IP Address: 192.168.0.5
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)
Time: 00:15 26th November
<<<<<------------END------------>>>>>
<<<<<------------BEGIN------------>>>>>
Site user came from: http://herproom.5.forumer.com/index.php?
IP Address: 192.168.0.5
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)
Time: 00:17 26th November
<<<<<------------END------------>>>>>
This cant all be same user as Ive been watching. Ip showing for all entries
•
•
•
•
Full-screenYour IP address is 192.168.0.5
City: Marina Del Rey California
Country: United States
Continent: North America
Time Zone: PST
Please help me do What Im trying to.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
If you use a <script> tag then you will get the URL/page where the <script> tag is in as the referer.
example: if index.php has:
<script src="spy.php">
Then you'll always get index.php as the referer. This is because the user was on index.php when the HTTP request for spy.php was made.
If you want to get the site the user came from, then you have to save their referer in index.php. You can either append this data to your script src, or save it directly.
eg:
in index.php use:
Then in referer.php retrieve the site the user came from via:
Or you can just include spy.php in your PHP file:
This reduces the HTTP requests/bandwidth to your server.
One thing I noticed is the your spy.php gives non-js output. This will cause any JavaScript debuggers on the HTTP Client (users browsers) to display error messages.
What you want to do is give out a header('Content-Type: text/js'); and also reduce output to a format such as JSON or just JS. If viewed directly, you can still read the output and thus do your own debugging...
example: if index.php has:
<script src="spy.php">
Then you'll always get index.php as the referer. This is because the user was on index.php when the HTTP request for spy.php was made.
If you want to get the site the user came from, then you have to save their referer in index.php. You can either append this data to your script src, or save it directly.
eg:
in index.php use:
<script src="spy.php?referer=<?php echo $_SERVER["HTTP_REFERER"]; ?>"></script>
Then in referer.php retrieve the site the user came from via:
$referer = $_GET['referer'];
Or you can just include spy.php in your PHP file:
include('spy.php');This reduces the HTTP requests/bandwidth to your server.
One thing I noticed is the your spy.php gives non-js output. This will cause any JavaScript debuggers on the HTTP Client (users browsers) to display error messages.
What you want to do is give out a header('Content-Type: text/js'); and also reduce output to a format such as JSON or just JS. If viewed directly, you can still read the output and thus do your own debugging...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Thanks Digital But It dosent seem to work now, did I mess it up? Please show me how to write it. I have
php
html
in my index.php?
<script src="http://h1.ripway.com/Inny/spy2/spy2.phpreferer=<?php echo $_SERVER["HTTP_REFERER"]; ?>"></script>
the output
http://h1.ripway.com/Inny/spy2/spy2.html
the index.php?
http://herproom.5.forumer.com/index.php?
php
<?php
$spy2 = fopen("spy2.html" , "a");
$time = date("H:i dS F");
fwrite($spy2,"<font color='blue'><<<<<------------BEGIN------------>>>>></font><br />");
fwrite($spy2,"<font color='black'>Site user came from:<b><font color='GREEN'> ".$_SERVER['HTTP_REFERER']."</font></b><br />");
fwrite ($spy2,"$referer = $_GET['referer'];$referer = $_GET['referer']."<br />;
fwrite($spy2,"IP Address: ".$_SERVER['REMOTE_ADDR']."<br />");
fwrite($spy2,"Browser: ".$_SERVER['HTTP_USER_AGENT']."<br />");
fwrite($spy2,$_SERVER['HTTP_USER_AGENT'].": ".$_SERVER['HTTP_USER_AGENT']."<br />");
fwrite($spy2,"Language: ".$_SERVER['HTTP_ACCEPT_LANGUAGE']."<br />");
fwrite($spy2,$_SERVER['HTTP_ACCEPT_CHARSET'].": ".$_SERVER['HTTP_ACCEPT_CHARSET']."<br />");
fwrite($spy2,$_SERVER['HTTP_ACCEPT_ENCODING'].": ".$_SERVER['HTTP_ACCEPT_ENCODING']."<br />");
fwrite($spy2,"Time: ".$time."<br />");
fwrite($spy2,"<font color='red'><<<<<------------END------------>>>>></font><p/><p>");
fclose($spy2);
?>html
<html> <title>Spy2</title> <head> </head><meta http-equiv="Content-Type" content="text/js; charset=UTF-8" /> <body background="http://i14.photobucket.com/albums/a345/Instar/escher_background.gif"> <center><font color='red'> <form method="POST" action="http://www.geobytes.com/IpLocator.htm?GetLocation"> <input type="hidden" name="cid" value="0"> <input type="hidden" name="c" value="0"> <input type="hidden" name="Template" value="iplocator.htm"> <h3>IP Address to locate:<input type="text" name="ipaddress" size="15" value=""> <input type="submit" value="Submit"> </h3> </form> </center>
in my index.php?
<script src="http://h1.ripway.com/Inny/spy2/spy2.phpreferer=<?php echo $_SERVER["HTTP_REFERER"]; ?>"></script>
the output
http://h1.ripway.com/Inny/spy2/spy2.html
the index.php?
http://herproom.5.forumer.com/index.php?
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
results still only showing index.php? pages !!
cant seem to get real ip addys?
cant seem to get real ip addys?
•
•
•
•
<<<<<------------BEGIN------------>>>>>
Site user came from: http://herproom.5.forumer.com/index.php?showtopic=4606
IP Address: 192.168.0.5
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705): Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
Language: en-us
:
gzip, deflate: gzip, deflate
Time: 04:38 28th November
<<<<<------------END------------>>>>>
<<<<<------------BEGIN------------>>>>>
Site user came from: http://herproom.5.forumer.com/index.php?
IP Address: 192.168.0.5
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hotbar 10.0.362.0)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hotbar 10.0.362.0): Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; Hotbar 10.0.362.0)
Language: en-au
:
gzip, deflate: gzip, deflate
Time: 04:38 28th November
<<<<<------------END------------>>>>>
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
Try a simple example first:
index.php
spy2.php
See if you get the correct referer.
note: You have to click on a link from a different page that points to index.php to get the referer as that page. Or you can simulate a HTTP GET for your index.php page by using telnet:
This way you can be sure of what is being received...
Open your command prompt/terminal/shell:
type in: telnet h1.ripway.com 80
type in: GET /index.php HTTP/1.1
press enter
type in: HTTP-Referer: http://example.com/referer.php
press enter
type in: HOST: domain.com
press enter
type in: Connection: close
press enter
press enter
Then go to your log.txt file to see if you got the correct referer.
index.php
<script src="http://h1.ripway.com/Inny/spy2/spy2.php?referer=<?php echo $_SERVER["HTTP_REFERER"]; ?>"></script>
spy2.php
<?php
file_put_contents('log.txt', 'Referer: '.$_GET['referer']."\n");
?>See if you get the correct referer.
note: You have to click on a link from a different page that points to index.php to get the referer as that page. Or you can simulate a HTTP GET for your index.php page by using telnet:
This way you can be sure of what is being received...
Open your command prompt/terminal/shell:
type in: telnet h1.ripway.com 80
type in: GET /index.php HTTP/1.1
press enter
type in: HTTP-Referer: http://example.com/referer.php
press enter
type in: HOST: domain.com
press enter
type in: Connection: close
press enter
press enter
Then go to your log.txt file to see if you got the correct referer.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Oh btw: you have to urlencode the HTTP referer since it may contain some url delimiters..
<script src="http://h1.ripway.com/Inny/spy2/spy2.php?referer=<?php echo urlencode($_SERVER["HTTP_REFERER"]); ?>"></script>
<script src="http://h1.ripway.com/Inny/spy2/spy2.php?referer=<?php echo urlencode($_SERVER["HTTP_REFERER"]); ?>"></script>
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Would it be possible to get the info I want and write to a log.txt using javascript instead?
seems my site has a problem parsing php?
or maybe its the host im using for spy.php?
I dont know of another free host that allows php, not sure what version of php my server supports.
seems my site has a problem parsing php?
or maybe its the host im using for spy.php?
I dont know of another free host that allows php, not sure what version of php my server supports.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
Ok if I use an Iframe instead of script tags, it will still write to the log but still not getting correct referrer
index.php
php
index.php
<iframe src="http://h1.ripway.com/Inny/spy2/spy2.php?referer=<?php echo urlencode($_SERVER["HTTP_REFERER"]); ?>"></iframe>
php
<?php
header("content-type: application/x-javascript");
$spy2 = fopen("spy2.html" , "a");
$time = date("H:i dS F");
$referer = $_GET['referer'];$referer = $_GET['referer'];
fwrite($spy2,"<font color='blue'><<<<<------------BEGIN------------>>>>></font><br />");
fwrite($spy2,"<font color='black'>Site user came from:<b><font color='GREEN'> ".$_SERVER['HTTP_REFERER']."</font></b><br />");
fwrite($spy2,"IP Address: ".$_SERVER['REMOTE_ADDR']."<br />");
fwrite($spy2,"Browser: ".$_SERVER['HTTP_USER_AGENT']."<br />");
fwrite($spy2,$_SERVER['HTTP_USER_AGENT'].": ".$_SERVER['HTTP_USER_AGENT']."<br />");
fwrite($spy2,"Language: ".$_SERVER['HTTP_ACCEPT_LANGUAGE']."<br />");
fwrite($spy2,$_SERVER['HTTP_ACCEPT_CHARSET'].": ".$_SERVER['HTTP_ACCEPT_CHARSET']."<br />");
fwrite($spy2,$_SERVER['HTTP_ACCEPT_ENCODING'].": ".$_SERVER['HTTP_ACCEPT_ENCODING']."<br />");
fwrite($spy2,"Time: ".$time."<br />");
fwrite($spy2,"<font color='red'><<<<<------------END------------>>>>></font><p/><p>");
fclose($spy2);
?> Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
Try using and include() instead of <script> in your index.php PHP and see what you get.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Windows server 2003 User creation problem (Windows NT / 2000 / XP / 2003)
- ASP.NET how can i display the logod user Status (ASP.NET)
- Login and retrieve user data from database (ASP.NET)
- Track the number of times a user logs in (ASP)
- Replacement slave HDD not recognised in BIOS (Storage)
- will someone please help me. (C)
- beginner (C++)
- I am a girl doing my 1st simple program (C)
- User Authorization (Java)
Other Threads in the PHP Forum
- Previous Thread: Need help with image upload
- Next Thread: Problem with creating scheduling program


Linear Mode