我已经将PHPurl安装了一个URL缩短器(从http://blondish.net/resources/scripts/phpurl/)到我的网站,并根据我的网站风格进行了自定义。
一切正常,除了每次添加一个数字生成URL ID。例如:。http://)jpine.co.uk/1然后转到。http://jpine.co.uk/2
我希望它看起来更像bit.ly并且有。http://jpine.co.uk/42t8hnf - 一个随机生成的数字。我不知道该怎么做但我相对肯定它在create.php中计算它。它在下面:
<?
include("config.php");
if (strstr($_SERVER['HTTP_REFERER'], $root));
else { header ("Location: $rooturl"); }
$ip = $_SERVER['REMOTE_ADDR'];
$url = mysql_real_escape_string($_POST['url']);
if(preg_match('|^http(s)?://[a-z0-9-]+(\.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url)) {
if (empty($_POST['tag'])) {
$query = mysql_query("INSERT INTO $table (ip,url) VALUES ('$ip','$url')") or die('MySQL error: '.mysql_error());
$qs = mysql_insert_id();
} else {
if (ereg('^[a-zA-Z0-9]+[a-zA-Z0-9]+$', $_POST['tag'])) {
$tag = mysql_real_escape_string($_POST['tag']);
$query = mysql_query("select * from $table where `tag` = '$tag';") or die('MySQL error: '.mysql_error());
if (mysql_num_rows($query) != 0)
die("This tag has already been used! Please press back button on your browser and choose another tag!");
else {
$query = mysql_query("insert $table (ip,url,tag) VALUES ('$ip','$url','$tag')") or die('MySQL error: '.mysql_error());
$qs = $tag;
}
} else
die('Your tag contains invalid characters! Only alphabets and numbers allowed! Please press back button on your browser and choose another tag!');
}
$link = $destination . $qs;
require 'create_template.php';
} else
echo 'URL is invalid';
?>
答案 0 :(得分:0)
不那么容易。你需要改变很多东西和数据库。
答案 1 :(得分:0)
你可以按照这里描述的方式尝试:short id's like YouTube or Tinyurl。