This could go a couple of ways depending on what the link is for. If the link is for a file, you can just have a cron job, or just a randomized check in your script remove files over 3 days old.
If it is just a link to a page, then it depends on what is being rendered for that page.
Here are some solutions for the page one.
1. If you use a database, just have a table with relevant data, you only need 2 columns minimum, Id and Date Created. When a user requests
www.site.com/index.php?id=1234 it will pull the data from database and check to see if it is more than 3 days old.
Then have your script randomly every now and then delete records older than the date created, or leave them, your choice.
2. Use Objects.
This is a creative way to do it, have one file, we will call link.class.php
CODE
<?php
class linkRegistry {
public $links = array();
public function addRecord($name){
array_push(&$this->links,$name);
}
public function save(){
$object = serialize($this);
// Write to file, DO NOT APPEND
}
public function restore(){
// Grab string from file
// $str = file_get_contents($file)
return unserialize($str);
}
public function clean(){
/**
* Check $this->links for old links and remove
* them
*/
}
public function getLink($id){
/**
* Search array for matching id
* and check date for being old.
*/
}
}
Now we have your main application, index.php
CODE
require_once('link.class.php');
$linkReg = linkRegistry::restore();
$id = abs($_GET['id']);
if($linkReg->getLink($id)){
// Link Is Valid
} else {
// Send user to generation page
}
Hope that helps ya
This post has been edited by joeyadms: 8 Jun, 2008 - 05:02 AM