-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
42 lines (39 loc) · 867 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
include "config.php";
function code62($x){
$show='';
while($x>0){
$s=$x % 62;
if ($s>35){
$s=chr($s+61);
}elseif($s>9&&$s<=35){
$s=chr($s+55);
}
$show.=$s;
$x=floor($x/62);
}
return $show;
}
function shorturl($url){
$url=crc32($url);
$result=sprintf("%u",$url);
return code62($result);
}
if(isset($_GET['url']))
{
$url=addslashes($_GET['url']);
$host="http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$sql = "select codeid from shorturl where url='$url'";
$query = mysql_query($sql);
if($row=mysql_fetch_array($query))
{
echo $host.$row['codeid'];
}
else
{
$new=shorturl($url);
echo $host.$new;
$sql = "insert into shorturl(codeid,url) values('$new','$url')";
$query = mysql_query($sql);
}
}