Unstoppable Domains

Creating a file

Spaceship Spaceship
Watch

Barrucadu

Established Member
Impact
64
In PHP whenever someone uploads a file I want it to create a [filename.fileextension].log file that stores the IP of the person who uploaded it, I have a getip function but dont know how to create the file.

PHP:
function getip()
    {
        global $_SERVER;
        if ($_SERVER['HTTP_X_FORWARD_FOR']) //stupid proxies! :P
        {
            return $_SERVER['HTTP_X_FORWARD_FOR']; //get there real ip hehe
        }
        else
        {
            return $_SERVER['REMOTE_ADDR']; //they dont use a proxy :)
        }
    }

PHP:
	 $ip = getip();
	 $folder = "./uploads/";
         //$newfile is the name of teh file they uploaded.
	 $logfile = $newfile.".log";
	 //create file somehow on this line called the value of $logfile
	 $handle = fopen($folder,$logfile);
	 fwrite($handle,$ip);
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
someone going to help me?
 
0
•••
I'd recommend storing these kinds of things in a database - the IP in the DB (lol sounds wierd) that references the file.
 
0
•••
Something like this? :)
PHP:
 $ip = getip();
     $logfile = "./uploads/iplog.log"; 
     $fp = fopen($logfile, "w+");     
     fwrite($fp, $ip);                   
     fclose($fp);
 
0
•••
Mikor said:
PHP:
$ip = getip();
	 $folder = "./uploads/";
         //$newfile is the name of teh file they uploaded.
	 $logfile = $newfile.".log";
	 //create file somehow on this line called the value of $logfile
	 $handle = fopen($folder,$logfile);
	 fwrite($handle,$ip);

If you do it that way your going to have a long list of files :/


I would suggest something like secondversion is doing, but also add the filename to the log. To add anything else, just add another piece to the array

ex:
PHP:
<?php
$data = array($newfile, getip());
$data = implode(",", $data); 
     $logfile = "./uploads/iplog.log"; 
     $fp = fopen($logfile, "a"); // the w+ places pointer at beginning of file     
     fwrite($fp, $data);                    
     fclose($fp);
?>
 
Last edited:
0
•••
Are you going to have a file for each visitor unique IP? weird. If you already use mySQL to store user info, you could just add another field for IP and set it at the time of registration.
 
0
•••
Hi doc,

$fp = fopen("filename.log","a+"); //Creates a File to Append
$rUser = $_SERVER['REMOTE_ADDR']; // User(s) Ip address

if(!$fp){ // Check to see if the File
print ("Could Not Create File."); // was Created if not exit
exit; //else continue loading instructions
}
fwrite($fp,$rUser,strlen($rUser)); // Write The User Ip Address
if(fclose($fp)){
print ("File Closed"); //Check the file was closed not
} //necessary but encouraged.
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back