Hello,

Thanks in advance to anyone who can answer this question.

Can I record a users ip address without them logging into my site?

I have a list of documents that I would like to make available and would like to get an idea of who may be viewing them.

What I would like to do is; when a user clicks a link, I would like to record the document_id, the date/time it was clicked and the ip address of the user. I'm pretty sure I can come up with the script, but before I begin I'm not sure if it is possible without user log-in.

again, thanks for any help.

-dottomm

Recommended Answers

All 6 Replies

That was a good article.

While I'm no guru at PHP, I would think that a user still has to be logged in and tracked through a session to log user specific data. I could be completely wrong though, that happens a lot 8-).

What I would try is writing a script and having a few friends try it out. The only way to tell :). The logging in part I believe you might be doing two thing 1) finding a mySQL entry and 2) Setting session variables of the clients log in information etc... Then again I might be wrong also. Good luck and please post if it works.

<?php

/**
 * @author Jeremy Boron
 * @copyright 2009
 * @company KRAZY GEEK DOT COM
 */




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

$q1 = "INSERT INTO ipsave (ip) VALUES ('".$ip."');";
		
		
		$query = mysql_query($q1);




?>

but you should be more specific what you want to do with the data or what it is for this seems just odd that you
would want to grab people's ip when they visit but let me know what your trying to do i can maybe help more

without even a database, used this code when analysing small sites

stats.php

<?php //stats.php
// Get the user stats.
$getdate = date( 'd-m-Y, H:i:s' );// Get the date time, trhis is a human readable (me) so did not use timestamp.
$user_ip = $_SERVER['REMOTE_ADDR'];// Get the users IP.
$user_browser = $_SERVER['HTTP_USER_AGENT']; // Get the browser type.
$referer = $_SERVER['HTTP_REFERER']; // Get the refering page.
$file = $_SERVER['PHP_SELF']; //get the currentfilename
// Look for the text file and open it for writting.
$file = "pathto/logfile.csv";// define the text file, named as .csv because excell will open csv and be sortable.
$fp = fopen($file, "a+");//open the text file for writing.
fputs ($fp, "$user_ip,$getdate, $referer, $file, $user\n"); // Write the user stats into the text file.
fclose($fp);// Close the text file.
?>

logfile.csv has to exist and be chmod to be writeable by the php user.
in the files you wish to trace

<?php include('pathto/stats.php'); ?>

Hi Everyone,

Thanks for all of your help.

This is solved and the answer is Yes, you can track a users IP without them being logged in.

thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.