Jump to content

How to make a link or page expire? with PHP


mcpb

Recommended Posts

I want to have a link or page expire at a set time.

How can I do this with PHP?

You know:
You go to one link/page
And after the expired time you get redirected to another page
and can’t access the first page any more.. Its locked out or something..



Thanks!
Link to comment
Share on other sites

Use the date function ...

[code]<?php
// has this expired?
$expire_date = "2007-01-03"; // good until Jan 3/07
$now = date("Y-m-d");
if ($now>$expire_date) {
    header("Location: not_this_page.php");
    die();
}
// and now the unexpired part of the page ...[/code]
Link to comment
Share on other sites

this wont count down, you'd need javascript for that... but this'll show you how much time is left
[code]
<?
$expires = strtotime("10 September 2007");

if(time()>$expires) echo 'page expired';
else{
$seconds = $expires-time();
while($seconds>15768000){
  $seconds -=15768000;
  $years++;
}
while($seconds>43200){
  $seconds -=43200;
  $days++;
}
while($seconds>3600){
  $seconds -=3600;
  $hours++;
}
while($seconds>60){
  $seconds -=60;
  $minutes++;
}
if(!empty($years)) $x .= ' '.$years.' years';
if(!empty($days)) $x .= ' '.$days.' days';
if(!empty($hours)) $x .= ' '.$hours.' hours';
if(!empty($minutes)) $x .= ' '.$minutes.' minutes';
$x .= ' '.$seconds.' seconds';
echo 'page exires in '.$x;
}
?>
[/code]
Link to comment
Share on other sites

If you want something to change after the page has loaded, you need javascript. It's okay, it doesn't bite too hard.

I don't know if PHP can create animated gifs - I know it does gifs, but the animation I don't know about. The only other option I see is to make an animated gif counting down.

Just use javascript ;)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.