Singleton is very basic design pattern.
If the instance is inited once than the class return the same instance.
Example of signleton in php5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <? Class SingletonExample { static private $instance; private function __construct() { } static function getInstance() { if(!Self::$instance) { Self::$instance = new SingletonExample(); } else { return Self::$instance } } public function doHello() { return "Hello World"; } ?> |
Usage Example:
1 2 3 4 5 6 | <? include_once("singleton.class.php"); $single = SingletonExample::getInstance(); echo $single->doHello(); //return "Hello World" ?> |
Garry`s One Time URL PHP5 Script
Hi,
I wrote little script + lib for one time url.
this script make MD5 hash string for one time using and redirect file.
the links looks like: http://garry-lachman.com/link/ce75f50f55bcedf0a72098a01764548bĀ and can be used one time only.
The url storing is based on PHP Sessions and link redirection on MOD_REWRITE but there is example
for non MOD_REWRITE using
Example of create of the link:
2
3
4
5
require_once("libs/one_time_url.lib.php");
$one_time_url = new one_time_url();
?>
<a href="<?php echo $one_time_url->make_url("http://www.garry-lachman.com"); ?>">This is one time URL to http://www.garry-lachman.com</a>
The code & example can be downloaded form here.
License: GNU/GPL (open source)