Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Free Download Email Signup

Status
Not open for further replies.

t5amec

Programmer
Aug 14, 2003
112
GB
I want to be able to send an automated email response (to a sign up) that has a link to a download file/page which expires after 48hrs.

Any tips please...

Make Sense? I hope so (-:
 
Put a datetime field in the database and populate it when the sign up occurs. Check that when you go to retrieve the information (file/page). If 48 hours has passed, echo a message stating it has expired.

Mark
 
I'm a complete ignoramus when it come to PHP and MySQL...

DATETIME... you're looking at an idiot

Please can you explain, or maybe point me to some tutorials,

Thanks

Make Sense? I hope so (-:
 
why not post the code you have already and we'll show you how to fix it.

we'll need the registration code, of course.
 
I want to send a link via email to the sign up address
eg.
which code is...
Code:
<?php
$email=$_GET["id"];
?>


<?php
$con = mysql_connect(connection info);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM expiring_link_signups WHERE email='$email'");

while($row = mysql_fetch_array($result))
  {
  echo $row['created_on'];
  }

?>

but i need to integrate this to determine weather or not the download is still valid...

Code:
<script>
var myDate=new Date();
myDate.setFullYear($row['created_on']);
var today = new Date();

if (myDate<today)
  {
  document.write("<meta http-equiv=REFRESH CONTENT='5; url=DOWNLOAD LINK'> </head><body>Your download should begin in five seconds.</body></html>");
  }
else
  {
  alert("Your download has expired");
  }
</script>

But i cant seem to get the two working together
...

Am i completely wrong?!?!?!

Make Sense? I hope so (-:
 
your expiring link table should look like this

Code:
create table if not exists
  expiring_link_signups (
id int(10) not null auto_increment primary key,
link varchar(255) not null,
userID int(10) not null,
ts timestamp DEFAULT CURRENT_TIMESTAMP
)

when you create a link record do the following

Code:
insert into expiring_link_signups
(id, link, userID)
values
(NULL, 'mylinkaddress', relevantuserID)

to serve a document that is time limited do something link the following. serving via javascript is unlikely to be security effective as you are providing a direct link (unless you redirect all link requests to a script via apache). if you are trying to control access store the resources outside the web root and use readfile to serve the information. remember to set the right headers using header().

Code:
$query = "select * from expiring_link_signups where userID='userID' and id='id' and  TIMESTAMPDIFF(SECOND,ts, now()) < 86400";
$results = mysql_query($query) or die (mysql_error());
if (mysql_num_rows() > 0 ){
  $row = mysql_fetch_assoc($results);
  //serve the file
  readfile($row['link']);
} else {
  echo 'no documents available to download';
}

pruneDatabase();

//this deletes expired links.
function pruneDatabase(){
  $query = "delete from expiring_link_signup where  TIMESTAMPDIFF(SECOND,ts, now()) >= 86400";
  mysql_query($query) or die (mysql_error());
}
 
i should add that i typed the code straight into the tek-tips box so there are bound to be typos and parse errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top