Take the 2-minute tour ×

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.mysite.com/page.php?unique=email@email.com

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

  3. He click/visit this newsletter/link.

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

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

I have this code



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

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

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

        $file = fopen('keys/keys','a');

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

Now what I want is to access http://www.site.com/generate.php?1234&s=email@email.com

And this this generate a unique link http://www.site.com/page.php?key525e1200e3a5f9.19949496&s=email@email.com

This is for a protected download page! I need to can 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 with $_GET['s']

Understand what I mean?

share|improve this question

closed as unclear what you're asking by Andrew Barber Oct 16 '13 at 0:05


What have you tried so far? –  Scott Helme Oct 15 '13 at 15:14
I found how to protect a download link using a unique URL. But I can't figure out how to use this script for my uses. –  Iulius Oct 15 '13 at 15:15
So what? Were's the question? –  idmean Oct 15 '13 at 15:17
Add a column in your database in your users table called unique_link. Have it default to 0. Have the page make sure the column is 0 to view the page, and when the user visits the page, set the column to 1. –  Aust Oct 15 '13 at 15:19
@ScottHelme The tutorial is not really good. The principles may apply, but using the old MySQL extension is not acceptable (the article is from 2012). –  ComFreek Oct 15 '13 at 15:27

1 Answer 1

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.

share|improve this answer
Easy to day, hard to do it, since I don't know PHP so well. –  Iulius Oct 15 '13 at 21:12
