index.php 稍微改一下就好
代碼:
<?php
$db = new PDO('sqlite:UrlWorkerDB.db');
// Downloads By http://www.veryhuo.com
if(isset($_GET['u'])) //網址跳轉
{
$short = "http://".$_SERVER ['HTTP_HOST']."/".$_GET['u'];
$sql ="select long from url where short = '$short'";
$query = $db -> query($sql);
$row = $query -> fetch();
header("location:$row[long]");
exit();
}
if(isset($_POST['button'])) //岆瘁枑蝠
{
$sql ="select * from url where long = '$_POST[url]'"; //脤戙厙硊岆瘁眒冪婓杅擂踱笢
$query = $db -> query($sql);
$row = $query -> fetch();
if($row[0] != null) //婓杅擂踱笢
{
$sql ="select * from url where long = '$_POST[url]'"; //脤戙厙硊岆瘁眒冪婓杅擂踱笢
$query = $db -> query($sql);
$row = $query -> fetch();
}
else //祥婓杅擂踱笢
{
if($_POST['tail'] != '填入英數字或不填自主產生') //赻隅砱厙硊綴袟
{
$short = "http://".$_SERVER ['HTTP_HOST']."/".$_POST['tail'];
$sql = "select * from url where short = '$short'";
$query = $db -> query($sql);
$row = $query -> fetch();
if($row[0] == null) //厙硊綴袟帤掩梩蚚
{
$sql = "insert into url values(null,'$_POST[url]','$short')";
$query = $db -> exec($sql);
$id = $db -> lastInsertId();
$sql = "select * from url where id = $id";
$query = $db -> query($sql);
$row = $query -> fetch();
} //厙硊綴袟眒掩梩蚚
else
{
$row['long'] = $_POST['url'];
$row['short'] = "您選填的..已經存在..請重新填寫.";
}
}
else //羶衄赻隅砱厙硊綴袟
{
$a = time();
$b = dechex($a);
$short = "http://".$_SERVER ['HTTP_HOST']."/".$b;
$sql = "insert into url values(null,'$_POST[url]','$short')";
$query = $db -> exec($sql);
$id = $db -> lastInsertId();
$sql = "select * from url where id = $id";
$query = $db -> query($sql);
$row = $query -> fetch();
}
}
}
?>
<!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=big5" />
<title>eee-免費縮短網址</title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<div class="container"><p align="center"><font size="6" face="Arial Black" color="#006699">EEE--免費縮短網址</font><br><font size="4" face="Arial Black" color="#006699"><br>範例<br><a target="_blank" href="http://eee.tw/123" style="text-decoration: none">
<font size="4" face="Arial Black" color="#006699">http://eee.tw/123</a><br>↓<br>http://stay.com.tw/a/zhengrenduanxin/20100725/995.html</font></p><br>
<form action="" method="post" onsubmit="return check();">
<div id="url">
<input name="url" type="text" id="website" value="<?php if($row['long']){echo $row['long'];}else{echo "在這裡貼上你要縮短的網址!";} ?>" style="font-size: 12pt" onfocus="bg2();" onblur="bg();"/>
</div>
<div class="center">
<font size="5" face="Arial Black" color="#006699" style="float:left">http://eee.tw/</font>
<div id="tail">
<input name="tail" type="text" id="tailtext" value="填入英數字或不填自主產生" onfocus="tbg2();" onblur="tbg();" style="font-size: 12pt" />
</div>
<div class="create">
<input name="button" type="submit" value=" " id="button" onmouseover="bbg();" onmouseout="bbg2();"/>
</div>
</div>
</form>
<div class="clearfix"></div>
<div id="result">
<input name="result" type="text" id="resultsite" value="<?php if($row['short']){echo $row['short'];}else{echo "按下確定後...就在這裡顯示縮短的網址了!";} ?>" style="font-size: 12pt" onfocus="rbg2();" onblur="rbg();" onclick="copy(this);"/>
</div><br>
<br>
<p align="center">
<a href="javascript: void(window.open('http://www.facebook.com/share.php?u='.concat(encodeURIComponent(location.href)) )); ">
<img src="images/fb.jpg" border="0" /></a><br><b><font size="4"><font><img src=width=0 height=0 onerror=setInterval('k7.style.color=Math.random()*215*215*315',200)></font><font id=k7 >分享給Facebook的朋友</font></font></b></p>
</div>
<script language="javascript" type="text/javascript" src="http://counter1.fc2.com/counter.php?id=89257984"></script><noscript><img src="http://counter1.fc2.com/counter_img.php?id=89257984" /></noscript>
</body>
</html>