Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create unique link (one time click) with expiration time [closed]

Tags:

php

I want to create unique links (one time click) for my newsletters.

Look the steps:

  1. I will create a link, or can be a script that will create the link http://www.example.com/[email protected]

  2. My subscriber will receive a newsletter which contains this link.

  3. They click/visit this newsletter/link.

  4. If they want visit it again they can't, the link will be expired, and the subscriber will be redirected to other page http://www.example.com/expired.php

So is there any chance to create this? How can this be accomplished?

I have this code

<?php

    include("variables.php");

    $password = trim($_SERVER['QUERY_STRING']);

    if($password == ADMIN_PASSWORD) {
        // Create a new key
        $new = uniqid('key',TRUE);

        if(!is_dir('keys')) {
            mkdir('keys');
            $file = fopen('keys/.htaccess','w');
            fwrite($file,"Order allow,deny\nDeny from all");
            fclose($file);
        }

        $file = fopen('keys/keys','a');
        fwrite($file,"{$new}\n");
        fclose($file);
?>

This script is located in a file named generate.php and if I access this url ( http://www.example.com/generate.php?1234 - 1234 is the password to generate a unique ID) will generate a unique link like this http://www.example.com/page.php?key525e1200e3a5f9.19949496 that will be only 1 time available!

Now what I want is, to access http://www.example.com/generate.php?1234&[email protected]

And this this generate a unique link http://www.example.com/page.php?key525e1200e3a5f9.19949496&[email protected]

This is for a protected download page! I need to add the user email to the download page, and this to be generated by link. 's' is the variable that will be get by the download page using $_GET['s']

Understand what I mean?

like image 756
Iulius Avatar asked Feb 03 '26 05:02

Iulius


1 Answers

I would do this using there email.

Then do a PHP page with the following statements. Request the GET (in this case the email address) and check if it exists in database table (lets call this - hasvisited).

IF this exists then redirect to page you want.

If doesnt exist then... 1.) Add it to DB. 2.) display 1 time page.

When step 1 happens. it will stop the user from visiting again.

If you want to restrict this to a group of specific users - as the above solution people could theoritcally type anything to get past this...

I would create table with the users already and do an IF state on a column called 'visits' and if 1 or less allow and add +1 to visits column. if above 1 visit then redirect.

I hope this make sense - should also be fairly simple to implement using PHP, MySQL DB and simple IF statement.

like image 68
Matt The Ninja Avatar answered Feb 04 '26 19:02

Matt The Ninja