在线短地址服务<?php
header("Content-Type:text/html;charset=utf-8");
define('Txpath', dirname(__FILE__).'/aytemp/'); //缓存目录
define('URL','http://127.0.0.4/'); //程序主域名
define('ANYOUAPI','anyou');
$pageb = mima('当前页码');
$mbox = '压缩后的网址:';
$MUM = new Mem();
$dangqian = $MUM -> g( $pageb);
if( !$dangqian ){
$dangqian = 1 ;$MUM -> s( $pageb,1);
} //当前url
if($_POST['url']){
$wz = mima($_POST['url']);
if($MUM -> g($wz)){ $zhi = $MUM -> g($wz); echo $mbox.URL.$zhi;
}
else{$danzhi = dechex($dangqian); $url = mima('@'.$danzhi); $MUM -> s($url,$_POST['url']);
$MUM -> s($wz, $danzhi);
$MUM -> j( $pageb,1); echo $mbox.URL.$danzhi;
$dangqian+=1;
}
}
if($_POST['yuan']){
$urlv = $MUM -> g(mima('@'.$_POST['yuan']));
if($urlv){
$urlv = str_replace("script",'',strtolower($urlv));
echo '还原后的网址:'.$urlv ;
}else
echo '网址没有压缩';
}
function arr2file($filename, $arr=''){
if(is_array($arr)){
$con = var_export($arr,true);
} else{
$con = $arr;
}
$con = "<?php \nreturn $con;\n";
file_put_contents($filename, $con);
}
function mima($var){
$varstr = strlen($var);
$hash = md5(md5(base64_encode($var.'13yd~!@#$%^&*(){}[1500]').$varstr));
return substr($hash,6,16);
}
function p(){
$args=func_get_args();
if(count($args)<1) return;
echo '
';
foreach($args as $arg){
if(is_array($arg)){
print_r($arg);
echo '
';
}else if(is_string($arg)){
echo $arg.'
';
}else{
var_dump($arg);
echo '
';
}
}
echo '
';}
class Mem{
//Memcache
//r(名,值) 替换值
//s(名,值,时间) 设置值
//g(名) 获取值
//a(名,值,时间) 新建立值 没有就新建 有就返回 false;
//d(名);删除值
//f(); 清空
//ja(名,数量);//减的数量
//j(名,数量);//加的数量
//gS();获取统计值
//gV();获得版本
private $md = null;
function __construct(){
$md = new Pxhc;
$this->md=$md;
}
public function r($key, $value){ //获取对象
return $this -> md -> replace( $key, $value);
}
public function s($key,$value,$time=0){ //设置值
return $this -> md -> set( $key, $value, MEMCACHE_COMPRESSED, $time);
}
public function g($key){ //获取值
return $this -> md -> get( $key);
}
public function a( $key, $value, $time=0){
return $this -> md -> add( $key, $value, MEMCACHE_COMPRESSED, $time);
}
public function d( $key){ //删除一个值
return $this -> md -> delete( $key); //删除一个值
}
public function f(){ //清空全部flush
return $this -> md -> flush();
}
public function ja( $key, $num=1){ //加法运算
return $this -> md -> decrement( $key, $num);
}
public function j( $key, $num=1){ //减法预算
return $this -> md -> increment( $key, $num);
}
public function gS(){ //获取进程池中所有进程的运行系统统计
return $this -> md -> getExtendedStats();
}
public function gV(){ //版本
return $this -> md -> getVersion();
}
public function error(){ //判断是否开启
$stats = $this -> md -> getStats();
if( empty( $stats )) return false;
else return true;
}
}
class Pxhc{ //文本缓存
public function replace($key, $value){ //替换规则
$pat = Txpath.$key.'.php';
if(file_exists( $pat)){
arr2file( $pat,$value);
return $value;
} else return false;
}
public function add($key, $value, $num='', $time){ //如果存在
$pat = Txpath.($key).'.php';
if(file_exists( $pat)) return false;
else{ arr2file( $pat,$value); return $value;}
}
public function increment($key,$num){ //加 条目
$pat = Txpath.urlencode($key).'.php';
if(file_exists($pat)){
$value = include $pat;
$value = $value*1+$num;
arr2file($pat,$value);
return $value;
}else return false;
}
public function getExtendedStats(){
$zzz = Txpath;
$nums = 0;
$mydir = dir($zzz); //读取配置文件
while($file = $mydir->read()){
if(($file != ".") and ($file != "..") and (strstr($file,".php"))){
$file = str_replace(".php",'',$file);
$files[] = $file;
$nums++;
}
}
$mydir -> close();
$files['Nums'] = '变量数:'.$nums.'个';
return $files;
}
public function decrement($key,$num){ //减 条目
$pat = Txpath.$key.'.php';
if(file_exists( $pat)){
$value = include $pat;
$value = $value*1-$num;
arr2file($pat,$value);
return $value;
}else return false;
}
public function get($key){ //获取值
$pat = Txpath.$key.'.php';
if(file_exists($pat)){
return include $pat;
}else return false;
}
public function delete($key){ //删除值
$pat = Txpath.urlencode($key).'.php';
if(file_exists($pat)){
unlink($pat);
return true;
}else return false;
}
public function flush(){ //删除全部
$zzz = Txpath;
$mydir = dir($zzz); //读取配置文件
while($file = $mydir -> read()){
if(($file!=".") and ($file!="..")){
$files=$zzz.$file;
unlink($files);
}
}
$mydir->close();
return true;
}
public function set($key, $value, $ss, $time){ //设置值
$pat = Txpath.$key.'.php';
if(!is_array($value))$value="'".$value."'";
arr2file($pat,$value);
return $value;
}
public function getVersion(){
return '0.0.1';
}
}
$PATHINFOS = ltrim(strtolower($_SERVER['PATH_INFO']),'/');
$urlv = $MUM -> g(mima('@'.$PATHINFOS));
if($urlv){
header('HTTP/1.1 302 Found');
header("Location: $urlv");
die;
}
?>
以压缩<?php echo $dangqian;?>个网址
网址压缩:
网址还原:
以上就是在线短地址服务的内容,更多相关内容请关注PHP中文网(www.php.cn)!
本文原创发布php中文网,转载请注明出处,感谢您的尊重!