Reply
Friday Thriller: A file that deletes itself
Old 04-04-2008, 06:11 PM Friday Thriller: A file that deletes itself
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 738
You might find this incredibly stupid, but I just wanted to see if this could be done. I give you...(drumroll) the file that deletes itself:

delete.php
PHP Code:
<?php

echo 'Click <a href="delete.php?act=delete">here</a> to delete this file.'

if ($_GET['act'] == 'delete') {

    
unlink('delete.php');
    
}

?>
How on earth might that be useful and why did you test that you may ask? You could create an install script that deletes itself when it is done making a configuration file and has checked that it was successful. I'm sure it's been done before and this is nothing earth-shattering, but there you go, it can be done and that's how you do it.
__________________
RSS Feed Tutorial
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
When You Register, These Ads Go Away!
Old 04-05-2008, 05:22 PM Re: Friday Thriller: A file that deletes itself
rogem002's Avatar
Webmaster Talker

Posts: 611
Name: Mike
Location: United Kingdom
I've never tried to do that! I'll try now!

*Test one, I got a syntax error. The code should be:
PHP Code:
<?php

echo 'Click <a href="delete.php?act=delete">here</a> to delete this file.';

if (
$_GET['act'] == 'delete') {

    
unlink('delete.php');
    
}

?>
*Second test, file deleted itself!

I might use this in the future Thanks!
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 

Last edited by rogem002 : 04-05-2008 at 05:27 PM.
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-07-2008, 01:51 AM Re: Friday Thriller: A file that deletes itself
mtishetsky's Avatar
King Spam Talker

Posts: 1,056
Name: Mike
Location: Mataro, Spain
unlink(__FILE__);
__________________
Free Mobile Phone Themes

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 04-07-2008, 12:08 PM Re: Friday Thriller: A file that deletes itself
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 738
Quote:
Originally Posted by rogem002 View Post
*Test one, I got a syntax error. The code should be:
Oops...I don't know how I missed that semicolon. Sorry.
__________________
RSS Feed Tutorial
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 04-07-2008, 12:13 PM Re: Friday Thriller: A file that deletes itself
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
lol i always knew it was possible...

my only guess why this isnt used in production install scripts is that they might want the user to be able to ensure it all works and then make them make the consious decsion to delete.

but still a thought to remember...

Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-07-2008, 12:16 PM Re: Friday Thriller: A file that deletes itself
VirtuosiMedia's Avatar
Webmaster Talker

Posts: 738
Quote:
Originally Posted by dansgalaxy View Post
my only guess why this isnt used in production install scripts is that they might want the user to be able to ensure it all works and then make them make the consious decsion to delete.
I don't know if I'll actually use it for that exact reason, but it is nice to know that it can be done...
__________________
RSS Feed Tutorial
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 04-07-2008, 12:18 PM Re: Friday Thriller: A file that deletes itself
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
I know
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-07-2008, 03:55 PM Re: Friday Thriller: A file that deletes itself
Ultra Talker

Posts: 298
haha thats quality, i will make it my life's purpose to use it somehow!
Tropica is offline
Reply With Quote
View Public Profile
 
Old 04-07-2008, 03:57 PM Re: Friday Thriller: A file that deletes itself
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
Quote:
Originally Posted by Tropica View Post
haha thats quality, i will make it my life's purpose to use it somehow!
*shakes head* what has the world come to? hehe
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-10-2008, 07:00 AM Re: Friday Thriller: A file that deletes itself
rogem002's Avatar
Webmaster Talker

Posts: 611
Name: Mike
Location: United Kingdom
Oh, I know why this works if your interested.

When the file is being processed, it's running the the RAM (thus it just loads that file) so you can delete and mess with the file as you wish
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-10-2008, 07:31 AM Re: Friday Thriller: A file that deletes itself
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
Isnt that obvious? well i gues not to some people

Lol... Hence why huge programs lag your ram so much and you cant run a 25mb program on a 64k system
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-10-2008, 09:25 AM Re: Friday Thriller: A file that deletes itself
rogem002's Avatar
Webmaster Talker

Posts: 611
Name: Mike
Location: United Kingdom
Quote:
Originally Posted by dansgalaxy View Post
Isnt that obvious? well i gues not to some people

Lol... Hence why huge programs lag your ram so much and you cant run a 25mb program on a 64k system
You would think so, but some people really are tech-t**ds. Anyway folkies, the above is why server's need a lot of RAM
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-10-2008, 10:21 AM Re: Friday Thriller: A file that deletes itself
nyef's Avatar
Ultra Talker

Posts: 267
Name: Lucas
If your script has access to delete files, so does any other script running on your website. Better make sure all your places to upload files or accept user input are protected from code injection.
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 04-10-2008, 10:35 AM Re: Friday Thriller: A file that deletes itself
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
i think in 99% of cases your scripts can execute unlink (and other stuff)

and you should always make sure ur upload folder has restricted rights or just dont allow upload of server executable files..
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-10-2008, 11:33 AM Re: Friday Thriller: A file that deletes itself
rogem002's Avatar
Webmaster Talker

Posts: 611
Name: Mike
Location: United Kingdom
I tend to CHMOD to file to 0000 as well as not allowing certain file types. Another good move (security wise) is to have the file below the public html, so it cannot be easily executed.
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-10-2008, 11:43 AM Re: Friday Thriller: A file that deletes itself
dansgalaxy's Avatar
Eat, Sleep, Code

Posts: 6,173
Name: Dan
Location: Swindon
only trouble with that is on systems you want the files to be avalible.

anyway i think we have completely gone off topic...

Dan
__________________
Personal UK Webhosting
Get 25% of ANY shared package for life ~ Promo: webmaster-talk (only for members!)
dansgalaxy is offline
Reply With Quote