-3

I have a message "my secret message" that I will type up on a html or php page. myexample.com/secretlink.html

How can I make it that when someone accesses my page a timer maybe with JS will start(easy part) but when timer is up it activates a code that destroys the page or maybe edits it, afterwards it tries to reload the page which will now not exist or not contain my message.

Only thing I found on Stackoverflow similar to this was "Website Self Destruct from Browser Bar"

Community
  • 1
  • 1
Sammy7
  • 364
  • 6
  • 21

3 Answers3

1

Here's a possible solution: store the message in an SQL table. Then, make the message available at a certain PHP page, say example.com/?qid=12345.

When the user requests the page, a flag will be set on that message in the database, saying that it has been viewed. Then, when the timer runs out, redirect to a delete page that will destroy the database row and redirect them (or tell them it has expired).

Finally, if the page is requested, and the flag saying that it has been viewed is already set, you can just destroy the message and say that it has already been claimed.

Alternatively, if you want it to just timeout after a certain amount of time, you can just add a "first_viewed_at" DATETIME field in the database, which, if it is too far in the past, causes the script to destroy the message.

Aeolingamenfel
  • 2,399
  • 1
  • 15
  • 22
1

Add the following ".htaccess" file, which will rewrite any .html request to add-delete.php. The page add-delete.php will handle the actual page deletion request.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ add-delete.php?request=%{REQUEST_URI} [L,QSA]
</IfModule>

Then have the add-delete.php require the file and then unlink() it. To learn more about unlink go to http://php.net/manual/en/function.unlink.php . The delete-page.php file would look like this:

<?php
// add check to prevent abuse
require($_GET["request"]);
unlink($_GET["request"]);
?>

However, I would probably leave the file up for a few minutes, just in case they hit refresh. In which case I would insert the clean request filename into a MySQL database table.

$db->bind("request",$_GET["request"]);
$db->query("INSERT INTO `delete_pages` (`page_name`) VALUES (:request);");

Then require the file. Then add a Crono event to run a PHP script that deletes all filenames in the table by running a unlink on each result.

$results = $db->query("SELECT `page_id`, `page_name` FROM `delete_pages` WHERE `timestamp` > NOW() - INTERVAL 1 MINUTE); // leave up for 1 or unlink asap

foreach($result as $row){
 unlink($row["page_name"]);
 $db->bind("page_id",$row["page_id"];
 $db->query("DELETE FROM `delete_pages` WHERE `page_id` = :page_id");
}

If you really wanted to do it with Javascript you could do a have a timer than send a xmlhttp request to the sever

<script> 
window.onload = function(page_name) { 
xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET","delete-page.php?page="+page_name, false); xmlhttp.send(null); document.getElementById("delete-update").value=xmlhttp.responseText; } 
</script>

I hope that helps.

hxtree
  • 187
  • 12
0

https://jsfiddle.net/68733393/

on page load just launch a function that will erase your secret after some time.

<div id='secret'>
  I am secret
</div>

setTimeout(function(){
  document.getElementById('secret').innerHTML = '';
}, 1000)
Alexei Darmin
  • 2,079
  • 1
  • 18
  • 30
  • This will still display "I am secret" each time the page is loaded – Krease Aug 23 '16 at 01:19
  • Oh I must have misunderstood, I can't tell if the message should only be visible one time or on every page load from the OP. I figured the 'page reloading' may have been a misbelief that one must reload a page to make content disappear when simple JS would do. – Alexei Darmin Aug 23 '16 at 01:24
  • @AlexeiDarmin Yes, I would like it to get deleted forever so if they try to reload the page nothing comes up. – Sammy7 Aug 23 '16 at 02:51