【问题标题】:I want to change the length of the shortened ID in PHPurl我想更改 PHPurl 中缩短的 ID 的长度
【发布时间】:2010-08-29 11:47:46
【问题描述】:

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

?>

【问题讨论】:

    标签: php mysql url short


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您可以按照此处描述的方式进行尝试:short id's like YouTube or Tinyurl

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多