Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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
Web Design Made Simple

Posts: 1,228
Trades: 0
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.
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
 
Register now for full access!
Old 04-05-2008, 05:22 PM Re: Friday Thriller: A file that deletes itself
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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!
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

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,226
Name: Mike
Location: Mataro, Spain
Trades: 0
unlink(__FILE__);
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

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
Web Design Made Simple

Posts: 1,228
Trades: 0
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.
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
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
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
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
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
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
Web Design Made Simple

Posts: 1,228
Trades: 0
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...
__________________
Want new web resources every day? - Follow me on
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
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
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I know
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
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
Trades: 3
haha thats quality, i will make it my life's purpose to use it somehow!
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

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
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
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
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
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
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
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
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
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
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
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
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
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: 265
Name: Lucas
Trades: 0
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
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
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..
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
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
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
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.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
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
Defies a Status

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

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

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-10-2008, 12:31 PM Re: Friday Thriller: A file that deletes itself
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
We have, we have. Yet I our large post counts counter our off topic-ness *Jokes*.

Oh "Thursday's Thriller: Making a loading bar with PHP/HTML/Images" - I've got a 'proof of concept' hanging about computer somewhere, let me find the code and post it
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-10-2008, 01:09 PM Re: Friday Thriller: A file that deletes itself
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
that would be something i would be interested in actually...


Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 04-10-2008, 01:36 PM Re: Friday Thriller: A file that deletes itself
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
that would be something i would be interested in actually...


Dan
http://www.webmaster-talk.com/php-fo...tml#post700827 - Posted it ^^
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-10-2008, 01:37 PM Re: Friday Thriller: A file that deletes itself
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
I haven't tested this and I don't think it could actually work because of looping reasons, but even more fun:

PHP Code:
 <?php

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

    
unlink('delete.php');
    echo 
'The file has been deleted. Click <a href="delete.php?act=create">here</a> to recreate it.';
    
} else if (
$_GET['act'] == 'create') {

        
$file"delete.php";
        
$handle fopen($file'w') or die("can't open file");
        
$code2 = <<<ThisIsNotGoingToWork

<?php

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

    unlink('delete.php');
    echo 'The file has been deleted. Click <a href="delete.php?act=create">here</a> to recreate it.';
    
} else if (
$_GET['act'] == 'create') {

        
$file= "delete.php";
        
$handle = fopen($file, 'w') or die("can't open file");
        
$code = $code2;
        fwrite(
$handle$code);
        fclose(
$handle);

} else {

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

}

?>

ThisIsNotGoingToWork;
        
fwrite($handle$code2);
        
fclose($handle);

} else {

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

}

?>
I'm sure there is some way to do something like that, but I'm not going to put a whole lot of time into it. The only possible use I could think of is if you accidentally had a file delete itself and wanted to reverse it.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Reply     « Reply to Friday Thriller: A file that deletes itself

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.04459 seconds with 12 queries