无论如何,通过PHP表单缩短URL


Anyway to shorten URL via PHP FORM?

我目前有人填写包含以下信息的表格:

  1. 您的姓名
  2. 收件人姓名
  3. 消息

我想知道当他们填写此信息时,我如何获得,并将其输入到链接中..例如,这是我现在正在使用的代码,它有效:

http://mywebsite.com/picture.php?to=" . $rname . "&from=" . $sname . "&message=" . $message . "&amount=" . $amount .

我现在想知道如何使该链接更短?也许有一个微小的网址API或其他东西?但是我该怎么做呢?

正如您已经强调的那样,执行此操作的最佳方法是通过 API。如果你安装了CURL,使用Tiny URL API实际上很容易:

function get_tiny_url($url)  {  
    $ch = curl_init();  
    $timeout = 5;  
    curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);  
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);  
    $data = curl_exec($ch);  
    curl_close($ch);  
    return $data;  
}
//test it out!
$your_url = 'http://mywebsite.com/picture.php?to=' . $rname . '&from=' . $sname . '&message=' . $message . '&amount=' . $amount;
$short_url = get_tiny_url($your_url);
//returns your tiny url
echo $short_url;