I want to create unique links (one time click) for my newsletters.
Look the steps:
I will create a link, or can be a script that will create the link http://www.example.com/[email protected]
My subscriber will receive a newsletter which contains this link.
They click/visit this newsletter/link.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With