Search code examples
javascriptphphtmloverwritedestroy

Code a webpage to self destruct after viewed


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"


Solution

  • 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.