0

我已经在我的网站上安装了 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';

?>
4

2 回答 2

0

没那么容易。你需要改变很多东西和数据库。

于 2010-08-29T12:01:48.443 回答
0

You could try it the way it's described here: short id's like YouTube or Tinyurl.

于 2010-08-29T14:01:01.763 回答