欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

超简单php短网址压缩免注册

程序员文章站 2022-04-15 15:19:12
...
php短网址压缩
本站短网址压缩可以帮你做什么?可以帮你把很长的网址压缩成 http://u.bitefu.net/wiHDH这样短的网址,使用方便,免注册!
代码超级简单,以下是全部代码!

[文件] index.php

<?php
header("content-Type: text/html; charset=utf-8");
$type = 1; // 0为bit.ly  1为goo.gl  2为is.gd  3为tinyurl.com  建议选1
$wjt = 1; //1为开启伪静态,0为关闭伪静态。开启伪静态后需要添加伪静态规则,规则请看说明
 
$urlarr = array('bit.ly','goo.gl','is.gd','tinyurl.com');
$myurl = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER["SCRIPT_NAME"];
$myurl1 = $myurl;
$myurl = str_replace('index.php','',$myurl);
if($wjt == 0){$myurl = $myurl.'?';}
 
function get_content($url){
    $chenqinghua_contents = file_get_contents($url);
    return $chenqinghua_contents;
}
$urlstr = $_SERVER['QUERY_STRING'];
if(strlen($urlstr)>3 && strlen($urlstr)<7 ){
    header("HTTP/1.1 301 Moved Permanently" );    
    header( "Location: http://".$urlarr[$type]."/".$urlstr); 
    exit;
}
 
if(isset($_POST['url'])){
    $url = $_POST['url'];
    $gourl = get_content('http://gold.sinaapp.com/go/urlget.php?from='.$myurl1.'&type='.$urlarr[$type].'&url='.urlencode($url),0);
    $aa = explode('/',$gourl);
    $surl = $myurl.$aa[3];
}
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>比特福短网址压缩,免费网址压缩!快速、稳定!|u.bitefu.net</title>
<meta name="keywords" content="网址压缩,短网址压缩,url压缩" />
<meta name="description" content="比特福短网址压缩u.bitefu.net,是国内专业的网址压缩网站,免注册!快速、稳定。做最好的网站压缩网站!" />
<style>body{font-size:13px;}a{color:#06C}a:hover{color:#F00;}
#box{background-color:#D0E1F2;border:1px solid #92C1E4;height:200px;line-height:20px;margin:20px auto 0;padding:100px 20px 20px;text-align:center;width:800px;}#guntian{border:1px dashed #CCC; background-color:#FFF; padding:10px; margin:10px auto; font-size:13px;}
#logo{margin:10px auto; text-align:center; font-size:40px;}#url{width:365px;*width:385px;}.btn{height:24px;}</style>
<script>function ck(){var urltxt = document.getElementById("url").value;if(urltxt.length<12){alert("请输入正确的网址!");return false;  }}
function cl(){document.getElementById("url").value = '';}</script>
<body>
<div id="logo"> <a href="http://www.bitefu.net" target="_blank" title="比特福免费短网址压缩">比特福免费短网址压缩</a></div>
<div id="box">
<form action="" method="post" onsubmit="return ck()">
  <strong>输入长的网址:</strong><br />
<input id="url" name="url" type="text" size="56" value="<?php echo $url;?>" />
<input type="submit" value="提交" class="btn" /> <input type="button" onclick="cl()" class="btn" value="清空" />
</form><br />
<?php if(strlen($surl)>6){echo '压缩后的网址:';}?> <a href="<?php echo $surl;?>" target="_blank"><?php echo $surl;?></a><br />
<br /><div id="guntian">
本站短网址压缩可以帮你做什么?可以帮你把很长的网址压缩成<?php echo $myurl;?>xxxx这样短的网址,使用方便,免注册!
</div></div>
<p align="center"><a href="http://www.bitefu.net" target="_blank">比特福精品汇聚</a> <a href="http://www.hbwanghai.com" target="_blank">网站建设</a></p>
<p align="center"><?=date("Y")?> @ bitefu.net</p>
<div style="display:none"><script language="javascript" type="text/javascript" src="http://js.users.51.la/3729735.js"></script></div>
</html>


[代码][PHP]代码

.htaccess伪静态规则
 
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php?URL
RewriteRule .* index.php?$0 [PT,L]