0

I have "5" users email, and I want to send them a Link for one time use, means if anyone click on that link rather than first time link should expire, How can we do this without access with database? Here is my current code (email.php)

$secret = "35onoi2=-7#%g03kl";
$email = urlencode($_POST['email']);
$hash = MD5($_POST['email'].$secret);
$link = "http://example.com/register.php?email=$email&hash=$hash";

In register.php there is only content/data,How can i check if someone already click on that link or not ?

amit
  • 1
  • 1
  • 18
  • 28
  • Without a persistent storage server-side, impossible. It *can* be an API elsewhere but ultimately something keep note of what links are used. – Martheen Aug 01 '22 at 05:14
  • @Martheen: is this possible with "create json file" (with using session ) ? – amit Aug 01 '22 at 05:16
  • Yeah, https://stackoverflow.com/questions/2662268/how-do-i-store-an-array-in-a-file-to-access-as-an-array-later-with-php – Martheen Aug 01 '22 at 05:25
  • Like Martheen said, you need a flag stored somewhere. if there is one browser only u can store in $_SESSION or $_COOKIE. that should be once, at least until the user reset the browser. – GeneCode Aug 01 '22 at 05:47
  • 1
    Storing the data into a (json) file is critical, because two or more users can do it at the same time and the second one can overwrite the file of the first one. Better is to use a database, e.g. `sqlite` for small things like this. – Wiimm Aug 01 '22 at 05:54
  • Just use a simple database, otherwise you'll cause yourself problems. Sqlite is a good choice if you can't/won't use any other database system – ADyson Aug 01 '22 at 06:02
  • @Wiimm how two or more users can overwrite the file ? Please explain – amit Aug 01 '22 at 06:10
  • 1
    To update a file you read the file, change the data, then write it back out. If they both run at the same time, they'll both read the original file, they'll each make their own changes, and write it out. The second write will not have the changes made by the first one. – Barmar Aug 01 '22 at 06:18
  • 1
    @parneet: first user ready the file and is paused, second user ready the file, modify it and write it back. First user modify it and write it back and override the changes of second user. – Wiimm Aug 01 '22 at 12:00

0 Answers0