[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 08-10-2005, 12:49 AM   #1 (permalink)
Barru.
 
Barrucadu's Avatar
 
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,731
78.50 NP$ (Donate)

Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold


Creating a file

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 Code:
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 Code:
     $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 by Mikor; 08-10-2005 at 01:01 AM.
Barrucadu is online now  
Old 08-10-2005, 05:43 AM   #2 (permalink)
Barru.
 
Barrucadu's Avatar
 
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,731
78.50 NP$ (Donate)

Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold


someone going to help me?
Barrucadu is online now  
Old 08-10-2005, 06:20 AM   #3 (permalink)
DNOA Member
 
mholt's Avatar
 
Join Date: May 2004
Location: Utah
Posts: 5,041
18.01 NP$ (Donate)

mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future

Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
I'd recommend storing these kinds of things in a database - the IP in the DB (lol sounds wierd) that references the file.
__________________
codeboards

A high-quality community of programmers -- Join today and post! We want new members!
mholt is offline  
Old 08-10-2005, 06:24 AM   #4 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Something like this?
PHP Code:
 $ip = getip();
     
$logfile = "./uploads/iplog.log";
     
$fp = fopen($logfile, "w+");     
     
fwrite($fp, $ip);                   
     
fclose($fp);
__________________
Eric is offline  
Old 08-10-2005, 07:37 AM   #5 (permalink)
NamePros Member
 
Join Date: Jan 2005
Location: Texas USA
Posts: 71
203.00 NP$ (Donate)

Outer is an unknown quantity at this point


Quote:
Originally Posted by Mikor
PHP Code:
$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 Code:
<?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);
?>
__________________
I wonder...

Last edited by Outer; 08-10-2005 at 07:46 AM.
Outer is offline  
Old 08-10-2005, 12:51 PM   #6 (permalink)
Senior Member
 
Porte's Avatar
 
Join Date: May 2005
Location: Somewhere on earth!
Posts: 3,528
21.30 NP$ (Donate)

Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of


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.
__________________
Custom WordPress theme design. Top notch free WordPress themes
Custom Theme Design
Porte is offline  
Old 08-20-2005, 03:40 AM   #7 (permalink)
NamePros Regular
 
Zubair1's Avatar
 
Join Date: Mar 2005
Posts: 874
159.45 NP$ (Donate)

Zubair1 is just really niceZubair1 is just really niceZubair1 is just really niceZubair1 is just really nice

AIDS/HIV
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.
__________________
Live Support : Zubair11 [at] hotmail.com
Free SEO Directory! || Free Games and Songs || eBloggy.net
Zubair.info || Mixcat Interactive
Zubair1 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: How to Install Apache2 MySQL and PHP on Windows deadserious Webmaster Tutorials 35 09-21-2005 09:46 PM
Tutorial: Creating a simple cgi hit counter for your site using Perl deadserious Webmaster Tutorials 3 05-29-2004 01:31 AM
Opening a text file and displaying the results in browser with PHP, Perl, and Python deadserious CODE 1 05-15-2004 07:58 PM
A simple cgi hit counter for your site using Perl deadserious CODE 2 11-07-2003 08:23 AM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 08:23 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85