Created
November 27, 2012 10:02
-
-
Save isS/4153421 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// vim: set et sw=4 ts=4 sts=4 fdm=marker ff=unix fenc=utf8 | |
* UniqueID 生成唯一的id | |
可用于在分布式服务器下生成唯一的id。 | |
* @author shaojianyi <issuoow@gmail.com> | |
*/ | |
class UniqueID { | |
public $u1; | |
public $u2; | |
public $u3; | |
public $u4; | |
public function __construct(){ | |
$this->u1 = $_SERVER['UNIQUE_ID']; | |
$this->u2 = $this->get_ip(); | |
$this->u3 = microtime(); | |
$this->u4 = rand(0,999999); | |
} | |
/** | |
* get_ip | |
* @return string | |
*/ | |
public function get_ip (){ | |
return isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; | |
} | |
public function get(){ | |
return md5($this->u1 . $this->u2 . $this->u3 . $this->u4); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment