You’d probably have heard of the mobile app Snapchat and perhaps the principles of how it works.
This design reminds me of that Mission Impossible “This tape will self-destruct” modus operandi. So, today, we set out using PHP to have a webpage be created by a user with their own textual content, that will exist on the rjmprogramming.com.au web server for up to three minutes before self destructing. The user can know this, or test this, by clicking a link labelled “own content” on this webpage they’ve created, and for up to three minutes that will not cause a web server 404 (not found) error, but then the webpage self-destructs. Or appears to anyway. The thing is, the HTML that is your webpage cannot achieve this even if it wanted too, but back when the user created that HTML webpage (perhaps with their own content) “destiny” had already set the wheels in motion to have that webpage be removed from the web server, with a combination of PHP functionalities, that go …
- file_put_contents(file, content) … creates the HTML content
- chmod(file, 0666) … allows any web server user permission to remove file
- file_put_contents(file.ksh, content to remove web page and itself using rm -f file file.ksh) … creates the HTML content
- chmod(file.ksh, 0777) … allows any web server user permission to execute and remove file.ksh
- exec(“at now + 2 minutes < file.ksh”) … sets up the underlying operating system to execute the “rm -f”‘s in 2 to 3 minutes
Voila! A self-destructing webpage. It is shareable with anyone in the world, not just the webpage creator during those 2-3 minutes, but then that’s it. It’s gone.
Now, above, we have written ideas with a Linux web server in mind, ours being an Apache/PHP/MySql CentOS web server, so with a Windows web server, commands like chmod would be handled by a Windows (DOS) command like attrib and rm -f would be achieved via the Windows command erase.
Here’s our proof of concept PHP web application with this at_poc.php source code.
If this was interesting you may be interested in this too.