lovephp Posted November 17, 2012 Share Posted November 17, 2012 guys how do i unlink a php file right after i access it. say i visit the file like www.somesite.com/file.php now the moment i access the file.php it should be deleted from the public_html how? Quote Link to comment https://forums.phpfreaks.com/topic/270839-unlink-a-php-file-right-after-accessing-it/ Share on other sites More sharing options...
Andy123 Posted November 17, 2012 Share Posted November 17, 2012 (edited) Take a look at this solution, which uses PHP's unlink function. I wasn't sure if you could use unlink in a script that is currently executing, but it appears that you can. Edited November 17, 2012 by Andy123 Quote Link to comment https://forums.phpfreaks.com/topic/270839-unlink-a-php-file-right-after-accessing-it/#findComment-1393277 Share on other sites More sharing options...
lovephp Posted November 17, 2012 Author Share Posted November 17, 2012 which answer? Quote Link to comment https://forums.phpfreaks.com/topic/270839-unlink-a-php-file-right-after-accessing-it/#findComment-1393278 Share on other sites More sharing options...
Andy123 Posted November 17, 2012 Share Posted November 17, 2012 The first one as I initially wrote in my post. I have edited the link to go straight to the answer. Quote Link to comment https://forums.phpfreaks.com/topic/270839-unlink-a-php-file-right-after-accessing-it/#findComment-1393281 Share on other sites More sharing options...
lovephp Posted November 17, 2012 Author Share Posted November 17, 2012 by just adding this line  unlink(__FILE__);  would do the job or i need to do it like  unlink(file.php); Quote Link to comment https://forums.phpfreaks.com/topic/270839-unlink-a-php-file-right-after-accessing-it/#findComment-1393282 Share on other sites More sharing options...
AyKay47 Posted November 17, 2012 Share Posted November 17, 2012 Using __FILE__ will allow you to delete files dynamically. unlink("somefile.php") will be static. May I ask why you are wanting to do this in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/270839-unlink-a-php-file-right-after-accessing-it/#findComment-1393283 Share on other sites More sharing options...
lovephp Posted November 17, 2012 Author Share Posted November 17, 2012 yes i have some secret code in the file.php which i would want to be gone for good when i access the file Quote Link to comment https://forums.phpfreaks.com/topic/270839-unlink-a-php-file-right-after-accessing-it/#findComment-1393284 Share on other sites More sharing options...
lovephp Posted November 17, 2012 Author Share Posted November 17, 2012 thanks works great Quote Link to comment https://forums.phpfreaks.com/topic/270839-unlink-a-php-file-right-after-accessing-it/#findComment-1393285 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.