2014-10-07 24 views
0

可我知道如何檢查的動態URL剩餘域內的用戶,讓他們被允許創建自己的網站,網址的同時爲用戶博客創建動態網址,我需要指定用戶可以創建的網址的可用性?

的步驟,我在下面: 1)通過文本框中,他們將能寫他們的暱稱/ personal_identity例如:說Custom_Blog

2)所以,我的網站域將是http://example.com/Custom_Blog/爲指定的用戶。

3)衝突:但我有一個在htaccess中創建的標籤「http://example.com/Custom_Blog」,用於編輯用戶的博客詳細頁面。

所以,當用戶在文本框中輸入時,我需要驗證url的可用性,無論url是否已被使用? 我想這個代碼是沒有幫助的,因爲它是獲取代碼302的網址是已經被用(存在):

$handle = curl_init($url); 
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); 

/* Get the HTML or whatever is linked in $url. */ 
$response = curl_exec($handle); 

/* Check for 404 (file not found). */ 
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); 
if($httpCode == 404 || $httpCode == 302) { 
    /* Handle 404 here. */ 
} 

curl_close($handle); 

回答

0

你可以對輸入字段中使用AJAX的驗證

平變化向php文件發送請求

在php文件中發送有關可用性的響應。

var dataString = {'url':value}; 
    $.ajax({ 
     type: "POST", 
     url: "somefile.php", 
     data: dataString, 
     success: function(data) { 
    // do some stuff here 
    } 
在PHP文件

獲得url,並檢查它

相關問題