NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Creating a file

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-10-2005, 01:49 AM THREAD STARTER               #1 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
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 :)
????: NamePros.com http://www.namepros.com/programming/114299-creating-a-file.html
        
}
    } 
PHP Code:
     $ip getip();
     
$folder "./uploads/";
         
//$newfile is the name of teh file they uploaded.
????: NamePros.com http://www.namepros.com/showthread.php?t=114299
     
$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 02:01 AM.
Barrucadu is offline  
Old 08-10-2005, 06:43 AM THREAD STARTER               #2 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
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 offline  
Old 08-10-2005, 07:20 AM   #3 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
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.
mholt is offline  
Old 08-10-2005, 07:24 AM   #4 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Something like this?
PHP Code:
 $ip getip();
     
$logfile "./uploads/iplog.log"
     
$fp fopen($logfile"w+");     
     
fwrite($fp$ip);                   
     
fclose($fp); 
????: NamePros.com http://www.namepros.com/showthread.php?t=114299
Eric is offline  
Old 08-10-2005, 08:37 AM   #5 (permalink)
NamePros Member
Join Date: Jan 2005
Location: Texas USA
Posts: 71
Outer is an unknown quantity at this point
 



Originally Posted by Mikor
PHP Code:
$ip getip();
????: NamePros.com http://www.namepros.com/showthread.php?t=114299
     
$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); 
????: NamePros.com http://www.namepros.com/showthread.php?t=114299
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($newfilegetip());
$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 08:46 AM.
Outer is offline  
Old 08-10-2005, 01:51 PM   #6 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
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.
__________________
WP Theme Developer
Your One-stop for Premium Magazine/CMS WordPress Themes
Deluxe Themes
Porte is offline  
Old 08-20-2005, 04:40 AM   #7 (permalink)
NamePros Regular
 
Zubair1's Avatar
Join Date: Mar 2005
Posts: 912
Zubair1 is just really niceZubair1 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
????: NamePros.com http://www.namepros.com/showthread.php?t=114299

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 Online TV || Tech Blog
Web Design & Web Development Services || Reliable Web Hosting
Zubair1 is offline  
Closed Thread


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


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 10:46 PM
2 Huge Name Forsale Vegas Entertainment Domains For Sale - Make Offer 9 09-21-2004 03:37 PM
Tutorial: Creating a simple cgi hit counter for your site using Perl deadserious Webmaster Tutorials 3 05-29-2004 02:31 AM
Opening a text file and displaying the results in browser with PHP, Perl, and Python deadserious CODE 1 05-15-2004 08:58 PM
A simple cgi hit counter for your site using Perl deadserious CODE 2 11-07-2003 09:23 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 01:16 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger