Jump to content

How to make a link or page expire? with PHP


mcpb

Recommended Posts

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]
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]
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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.