#12
|
|||
|
|||
引用:
Most of our services are free, however, we do have some premium URLs that will charge you a small fee for a limited time. The fee is supporting our most free services and prevent people who might abuse or spam on our services. 原文網址: http://www.meaningfulurl.com/faq.php |
#13
|
|||
|
|||
我修改了這個程式,讓使用者可以自訂短址名稱
示範網站如下,但程式可能隨時會再修改,資料庫也隨時都會更新,所以試用的轉址隨時會取消; http://to.waterworld.tw 以下為修改的地方供大家參考; 1. 下載安裝程式,請至下面網址下載: http://blog.zakka.tw/read.php?227 2. 依照指示安裝 3. 在index.php檔案中,找到<strong>Enter a long URL to make it shorter:</strong><br /><input type="text" name="url" size="40" /><br />在下面一行加上<br />please input a name for your short url:<input type="text" name="url2" size="40" /><br /> 4. 在create.php檔案中進行跟步驟三同樣的修改 5. 在global.php檔案中,將function generate_url() { $keys = "23456789abcdefghkmnpqrstvwxyz"; $i = 0; $url = ""; while ($i < 6) { $random = mt_rand(0, strlen($keys) - 1); $url .= $keys{$random}; $i++; } return $url; 以 function generate_url() { $url = $_POST['url2']; return $url;}取代 6. 在forwward.php檔案中將if (preg_match("/^[0-9a-z]{6}$/", $i)) { db_connect(); $suffix = $i{0}; $result = mysql_query("SELECT url FROM url_{$suffix} WHERE short_url = '$i'") or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_row($result); header("Location: ".stripslashes(str_replace(",", "%2C", $row[0]))); exit; } } 以 db_connect(); $suffix = $i{0}; $result = mysql_query("SELECT url FROM url_{$suffix} WHERE short_url = '$i'") or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_row($result); header("Location: ".stripslashes(str_replace(",", "%2C", $row[0]))); exit; } 取代 7. 最後,將網站目錄中的.htaccess中的RewriteCond %{REQUEST_URI} \/([0-9a-z]{6})$ [NC] 改成 RewriteCond %{REQUEST_URI} \/([0-9a-z]+)$ [NC] 8. 大功告成 將原本亂數產生的短網址改為可以自訂後,發現若是有人使用同一名稱,網站就會一直呈現連線中無法運作,這是要再改進的地方。 |