Heim >php教程 >PHP源码 >在线短地址服务

在线短地址服务

PHP中文网
PHP中文网Original
2016-05-25 17:08:321924Durchsuche

在线短地址服务

<?php
header("Content-Type:text/html;charset=utf-8");

define(&#39;Txpath&#39;, dirname(__FILE__).&#39;/aytemp/&#39;);  //缓存目录

define(&#39;URL&#39;,&#39;http://127.0.0.4/&#39;); //程序主域名

define(&#39;ANYOUAPI&#39;,&#39;anyou&#39;);

$pageb = mima(&#39;当前页码&#39;);

$mbox = &#39;压缩后的网址:&#39;;

$MUM = new Mem();

$dangqian = $MUM -> g( $pageb);

if( !$dangqian ){
  $dangqian = 1 ;$MUM -> s( $pageb,1);
}  //当前url



if($_POST[&#39;url&#39;]){ 
$wz = mima($_POST[&#39;url&#39;]);

if($MUM -> g($wz)){ $zhi =  $MUM -> g($wz); echo  $mbox.URL.$zhi; 
}
else{$danzhi =   dechex($dangqian); $url = mima(&#39;@&#39;.$danzhi); $MUM -> s($url,$_POST[&#39;url&#39;]);
 $MUM -> s($wz,   $danzhi); 
$MUM -> j( $pageb,1);  echo   $mbox.URL.$danzhi;
$dangqian+=1;
}

}


	
if($_POST[&#39;yuan&#39;]){
		
$urlv = $MUM -> g(mima(&#39;@&#39;.$_POST[&#39;yuan&#39;]));
		
if($urlv){
$urlv = str_replace("script",&#39;&#39;,strtolower($urlv));
 
	echo &#39;还原后的网址:&#39;.$urlv ;

}else
  echo &#39;网址没有压缩&#39;;


}



function arr2file($filename, $arr=&#39;&#39;){
	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.&#39;13yd~!@#$%^&*(){}[1500]&#39;).$varstr));
   return substr($hash,6,16);
	 
 }


function p(){
	 $args=func_get_args();
	 if(count($args)<1) return;
	 echo &#39;<p style="width:100%;text-align:left"><pre class="brush:php;toolbar:false">&#39;;

	foreach($args as $arg){
		if(is_array($arg)){  
			  print_r($arg);
			  echo &#39;<br>&#39;;
		  }else if(is_string($arg)){
			echo $arg.&#39;<br>&#39;;
		  }else{
			var_dump($arg);
			echo &#39;<br>&#39;;
		  }
		}
		    echo &#39;

'; } 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中文网(www.php.cn)!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn