【问题标题】:while creating a dynamic url for user blogs i need to specify the users for the availability of url's that they can create?在为用户博客创建动态 url 时,我需要为用户指定他们可以创建的 url 的可用性?
【发布时间】:2014-12-01 21:56:11
【问题描述】:

我可以知道如何检查域内用户的动态 url 可用性,以便他们可以创建自己的站点 url

我正在遵循的步骤: 1) 通过文本框,他们将能够写下他们的昵称/personal_identity 例如:说 Custom_Blog

2) 因此,对于指定用户,我的网站域将是 http://example.com/Custom_Blog/

3)冲突:但我确实在 htaccess 中创建了一个选项卡“http://example.com/Custom_Blog”链接,用于编辑用户的博客详细页面。

所以,当用户在文本框中输入时,我需要验证 url 的可用性,无论该 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);

【问题讨论】:

    标签: php ajax .htaccess mod-rewrite curl


    【解决方案1】:

    您可以使用 ajax 进行验证

    在该输入字段上的 onchange 向 php 文件发出请求

    在 php 文件中发送关于可用性的响应。

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

    在 php 文件中获取 url 并检查它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      • 2016-02-12
      • 2022-08-08
      • 1970-01-01
      • 1970-01-01
      • 2020-07-12
      • 2014-06-04
      相关资源
      最近更新 更多