{"id":31068,"date":"2017-07-01T03:01:43","date_gmt":"2017-06-30T17:01:43","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=31068"},"modified":"2017-08-11T18:22:29","modified_gmt":"2017-08-11T08:22:29","slug":"webpage-that-self-destructs-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/webpage-that-self-destructs-primer-tutorial\/","title":{"rendered":"Webpage that Self-Destructs Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/at_poc.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Webpage that Self-Destructs Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/self_destruct.jpg\" title=\"Webpage that Self-Destructs Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">Webpage that Self-Destructs Primer Tutorial<\/p><\/div>\n<p>You&#8217;d probably have heard of the mobile app <a target=_blank title='Snapchat' href='https:\/\/www.snapchat.com\/'>Snapchat<\/a> and perhaps the principles of <a target=_blank title='How Snapchat works' href='http:\/\/www.pocket-lint.com\/news\/131313-what-s-the-point-of-snapchat-and-how-does-it-work'>how it works<\/a>.<\/p>\n<p>This design reminds me of that Mission Impossible <a target=_blank title='?' href='https:\/\/www.youtube.com\/watch?v=0TiqXFssKMY'>&#8220;This tape will self-destruct&#8221;<\/a> 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 &#8220;own content&#8221; on this webpage they&#8217;ve created, and for up to three minutes that will not cause a web server <a target=_blank title='404 error information from computerhope' href='https:\/\/www.computerhope.com\/jargon\/num\/404.htm'>404<\/a> (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) &#8220;destiny&#8221; 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 &#8230;<\/p>\n<ul>\n<li><a target=_blank href='http:\/\/www.php.net\/manual\/en\/function.file-put-contents.php' title='file_put_contents'>file_put_contents<\/a>(<i>file<\/i>, <i>content<\/i>) &#8230; creates the HTML content<\/li>\n<li><a target=_blank title='chmod help from computerhope' href='https:\/\/www.computerhope.com\/unix\/uchmod.htm'>chmod<\/a>(<i>file<\/i>, 0666) &#8230; allows any web server user permission to remove <i>file<\/i><\/li>\n<li>file_put_contents(<i>file<\/i>.ksh, <i>content<\/i> to remove web page and itself using <i><a target=_blank title='rm help from computerhope' href='https:\/\/www.computerhope.com\/unix\/urm.htm'>rm<\/a> -f <i>file<\/i> <i>file<\/i>.ksh<\/i>) &#8230; creates the HTML content<\/li>\n<li>chmod(<i>file<\/i>.ksh, 0777) &#8230; allows any web server user permission to execute and remove <i>file<\/i>.ksh<\/li>\n<li><a target=_blank title='PHP exec() method information' href='http:\/\/php.net\/manual\/en\/function.exec.php'>exec<\/a>(&#8220;<a target=_blank title='at help from computerhope' href='https:\/\/www.computerhope.com\/unix\/uat.htm'>at<\/a> now + 2 minutes < <i>file<\/i>.ksh&#8221;) &#8230; sets up the underlying operating system to execute the &#8220;rm -f&#8221;&#8216;s in 2 to 3 minutes<\/li>\n<\/ul>\n<p>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&#8217;s it.  It&#8217;s gone.<\/p>\n<p>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 <i>chmod<\/i> would be handled by a Windows (DOS) command like <i><a target=_blank href='https:\/\/www.computerhope.com\/attribhl.htm' title='attrib info from computerhope'>attrib<\/a><\/i> and <i>rm -f <\/i> would be achieved via the Windows command <i><a target=_blank href='https:\/\/www.computerhope.com\/erasehlp.htm' title='erase info from computerhope'>erase<\/a><\/i>.<\/p>\n<p>Here&#8217;s our proof of concept PHP <a target=_blank href=\"HTTP:\/\/www.rjmprogramming.com.au\/PHP\/at_poc.php\" title=\"Click picture\">web application<\/a> with this  <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/at_poc.php_GETME\" title=\"at_poc.php_GETME\">at_poc.php<\/a> source code.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d31068' onclick='var dv=document.getElementById(\"d31068\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/php\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d31068' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;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 &#8220;This tape will self-destruct&#8221; modus operandi. So, today, we set out using PHP to have &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/webpage-that-self-destructs-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[2245,135,234,405,576,707,932,997,1319,1411,1418],"class_list":["post-31068","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-at","tag-batch","tag-command-line","tag-exec","tag-html","tag-linux","tag-php","tag-programming","tag-tutorial","tag-web-server","tag-webpage"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/31068"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=31068"}],"version-history":[{"count":3,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/31068\/revisions"}],"predecessor-version":[{"id":32085,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/31068\/revisions\/32085"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=31068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=31068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=31068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}