...

View Full Version : IP Log



newline
06-04-2007, 01:03 AM
Hey,


I know the usual IP log script and need some help on improving on it. I have a simple file uploading script and I want to beable to view the IP of whoever uploaded a certain file.



For example theres a file named "computer343.gif" and I want to beable to view the ip which uploaded it. Any Ideas

rafiki
06-04-2007, 01:14 AM
are you using a database to store the image?

newline
06-04-2007, 03:20 AM
nope a directory

whizard
06-04-2007, 03:22 AM
create a text file with the same name as the image (obviously a different extension, though) and store the IP in it

of course, ideally, this would be done, as rafiki suggested, with a database

Dan

_Aerospace_Eng_
06-04-2007, 03:27 AM
Or store the image file path and ip address in a database and the actual image in the directory? That would probably be the better thing to do.

whizard
06-04-2007, 03:29 AM
Or store the image file path and ip address in a database and the actual image in the directory? That would probably be the better thing to do.

How else would you use a database?

Dan

mr e
06-04-2007, 03:34 AM
How else would you use a database?

Dan
As opposed to storing the raw image data in the database

whizard
06-04-2007, 03:37 AM
Ahhhh....

What would be a good reason to do that - as in, why is that feature available?

Dan

newline
06-04-2007, 03:47 AM
Well iam not going to use a db im already done the coding, so how do you appose I do this?


Something easy :P

_Aerospace_Eng_
06-04-2007, 03:49 AM
As opposed to storing the raw image data in the database
Yeah I've heard good and bad things about doing that. It seems like it would take up too many resources to retrieve the image from the database. Then you have things like caching and what not.


Well iam not going to use a db im already done the coding, so how do you appose I do this?


Something easy :P
If you are wanting this to be easy then why are you even doing this at all? The easiest suggestion was that of whizard in post #4.

newline
06-04-2007, 04:15 AM
so have a system like when a new file is uploaded a text file is created which stores the ip?

whizard
06-04-2007, 04:19 AM
yeah...

something like



$fh = fopen("text_ips/SAME NAME AS IMAGE HERE.txt","w");
fwrite($fh,$_SERVER['REMOTE_ADDR']);
fclose($fh);


HTH
Dan

newline
06-04-2007, 04:28 AM
then I would just use a fopen to view the I.P?

whizard
06-04-2007, 04:33 AM
Actually, you could do this as well:

(to store the IP at the same time as the photo upload)


$fh = fopen("text_ips/SAME NAME AS IMAGE HERE.inc","w");
$data = "\$ip = ".$_SERVER['REMOTE_ADDR'];
fwrite($fh,$data);
fclose($fh);


(to retrieve the IP)


include("text_ips/SAME NAME AS IMAGE HERE.inc");
print $ip;


HTH
Dan

newline
06-04-2007, 04:38 AM
Alright


So in my upload script when the file is uploaded it will create a new .txt file which saves the ip to it.

whizard
06-04-2007, 04:41 AM
Yes, assuming you add the code I provided

Dan

newline
06-04-2007, 04:45 AM
so

fwrite

$_POST["filename"].txt
$_SERVER['REMOTE_ADDR'];

whizard
06-04-2007, 04:47 AM
$fh = fopen($_POST['filename']."inc","w");
fwrite($fh,$_SERVER['REMOTE_ADDR']);
fclose($fh);

HTH
Dan

newline
06-04-2007, 04:49 AM
well if the "filename" is pic1.gif wont it write that file, dont we want it to write a .txt file?

whizard
06-04-2007, 04:59 AM
good point:



$filename = explode(".",$_POST['filename']);
$fh = fopen($filename[0]."txt","w");
fwrite($fh,$_SERVER['REMOTE_ADDR']);
fclose($fh);


HTH
Dan

newline
06-04-2007, 05:04 AM
awesome it works thx!

whizard
06-04-2007, 05:06 AM
no problem, glad you got it sorted out!

:thumbsup:

Dan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum