Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,680 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,215 people online right now. Registration is fast and FREE... Join Now!




creating a link active over a specific period of time

 
Reply to this topicStart new topic

creating a link active over a specific period of time, send by mail

the chaser
post 8 Jun, 2008 - 02:15 AM
Post #1


New D.I.C Head

*
Joined: 8 Jun, 2008
Posts: 2


My Contributions


I'm on of those who just started programming php and asp. At the moment I'm trying to create a link which would work for 3 days, exceeding this time will send you back to the page where you generated the link. Is there anyone who could set me going in the right direction? Do I need the use of cookies?

thanks in advance

This post has been edited by the chaser: 8 Jun, 2008 - 02:17 AM
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 8 Jun, 2008 - 04:57 AM
Post #2


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 145



Thanked 6 times

Dream Kudos: 600

Expert In: PHP, Web Security

My Contributions


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
User is offlineProfile CardPM

Go to the top of the page

the chaser
post 8 Jun, 2008 - 06:00 AM
Post #3


New D.I.C Head

*
Joined: 8 Jun, 2008
Posts: 2


My Contributions


Thanks, I'll try the OO way as it suits the way I intended. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:44AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month