Help - Search - Members - Calendar
Full Version: VISITOR
Pixel2Life Forum > Member Tutorials and Requests > Forum Tutorial Archives > PHP Tutorials
fgd46tgh7ddd
Hi

If you have a website and you want to know when a visitor visits your website or if you want to know who is your website visitor or if you want to know your website visitor’s IP address, and more information about visitors, follow this tutorial

1 - If (main page is PHP) {
// add the code below into the php page

CODE
<?php
$browser = $_SERVER['HTTP_USER_AGENT']; // visitor’s browser
$ip = $_SERVER['REMOTE_ADDR']; // visitor’s IP Address
$date = date("Y / m / d"); // date of visit
$time = date("H : i : s"); // time of visit
$subject = "I’m a Visitor"; // mail subject
$email = "NRG@PRO "; // it’s not necessary to be a correct address
$message = " browser = $browser \n ip      = $ip \n date    = $date \n time    = $time";
mail( "Your Email address Here", "$subject", "$message", "From: $email" );
?>


2 - } Else if (main page is not PHP) {
// add the code below into the main page

CODE
<p><?php
$browser = $_SERVER['HTTP_USER_AGENT']; // visitor’s browser
$ip = $_SERVER['REMOTE_ADDR']; // visitor’s IP Address
$date = date("Y / m / d"); // date of visit
$time = date("H : i : s"); // time of visit
$subject = "I’m a Visitor"; // mail subject
$email = "NRG@PRO "; // it’s not necessary to be a correct address
$message = " browser = $browser \n ip      = $ip \n date    = $date \n time    = $time";
mail( "Your Email address Here", "$subject", "$message", "From: $email" );
?></p>

}


Comment it and tell me you problems.

Have fun
Zenom
This is cool but I have a question.

Using this script, will you be sent an email every time someone visits your site? What if the same user visits the same 10 times a day; will 10 emails be sent?

And isnt there a possibility that someone could launch a DoS attack to your site, and if it does send emails per visitor, wont that spam your inbox?

Sorry if I sounded rude but I wanted to know before I use this script.
DanWilliamson
Hey,

I think your correct therfore this script isn't much good really I'm sure you could do this through Mint.

- Dan

QUOTE(Speed @ Feb 12 2006, 06:05 AM) *
This is cool but I have a question.

Using this script, will you be sent an email every time someone visits your site? What if the same user visits the same 10 times a day; will 10 emails be sent?

And isnt there a possibility that someone could launch a DoS attack to your site, and if it does send emails per visitor, wont that spam your inbox?

Sorry if I sounded rude but I wanted to know before I use this script.
Arutha
if you use shared hosting this script would prob get your account locked, depending on how many emails it sends out an hour because most shared hosts will prevent your account from using over a certain percentage off the CPU.

And some explination into what you've actually coded would be good rather than just posting code snippets

Arutha
Joeydabomb
You could also use:

CODE
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$host = gethostbyaddr($ip);
$dtime = date('F jS Y, h:iA');

if($agent == ""){
$agent = "None";
}
if($uri == ""){
$uri = "None";
}
if($ip == ""){
$ip = "None";
}
if($host == ""){
$host = "None";
}
if($ref == ""){
$ref = "None";
}
if($dtime == ""){
$dtime = "None";
}


$entry_line = "
[Date] $dtime
[IP] $ip
[Host] $host
[Browser] $agent
[URL] $uri
[Referrer] $ref
---------------------------------------------------
";
$fp = fopen("users.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
?>


This will log every user with the details you want and will save it to a .txt file.

Remember to CHMOD to 777
liveman
Actually wouldn't it be easier just to make it put it into a db each time, and then login to an admin panel ...and view it smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.