PHP serverside: creating dynamic filenames

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phyzar
Forum Newbie
Posts: 2
Joined: Sun Nov 07, 2004 10:26 pm

PHP serverside: creating dynamic filenames

Post by phyzar »

Greetings,
I used to post alot on devshed, but looks like they dropped their forum... their loss.

I have the following in a php script...


Code: Select all

<?php

//CREATE LOG FILE 
$dd=date("d F Y H:i"); 
$fp = fopen ("../files/mylogfile.log", "a"); 
fputs ($fp, "$taga||order details:|$order \n $dd"); 
fclose ($fp); 

?>


hacked back but you get the general idea. This creates the log on our secure space. However you can reference this log even from a browser, if you know which URL to enter.

My thought would be to create a *.log file which is different and unique each time it is created - using the UNIX timestamp / MD5 checksum or something as the file name.

Can someone please point me in the direction of creating such a thing?

many thanks
JD
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Well simply use the timestamp and md5 hash as the name.

Code: Select all

$file = md5(time());
To stop people from just opening your files why not just add a .htaccess file to that directory to stop access? Then your log files names could be more meaningful.
phyzar
Forum Newbie
Posts: 2
Joined: Sun Nov 07, 2004 10:26 pm

champ!

Post by phyzar »

I had forgotten about .htaccess.

Not sure if this was the best way, but I just created a .htaccess file with "deny from all" inside of it. - allows server scripts to access the directory, but not through the browser. Comes back with the 403 error: Forbidden.

i can still download my logs via FTP software, but none of the 3 programs I have can see the .htaccess file. I assume only telnet or the like can see them. I didn't chmod the .htaccess as 644, i assume that will be ok.


Perfecto!
Thanks a million kd!
JD
Post Reply