【问题标题】:Problem with CURL fetch functionCURL 获取功能的问题
【发布时间】:2010-10-18 04:01:01
【问题描述】:

我创建了一个允许删除用户属性的 php 脚本。该脚本首先查找与用户关联的所有属性,然后循环删除所有属性。

当我为某个用户运行此程序时,它会进入 foreach 循环并打印出所有属性 ($name2) 但它似乎卡在 curl_fetch 部分。然后,当我尝试提取属性时,它们仍然为用户存在。任何想法为什么会发生这种情况?代码如下,供您查看。提前致谢。

 <?php

    $user=$_GET['userid'];
    $user_id=str_replace(array('@', '#'), array('%40', '%23'), $user);

    print "User-id: $user";
    print "<br /><br />";

    $url=("https://admin:password@oursite.com/@api/users/=$user_id/properties");
    $xmlString=file_get_contents($url);

    $delete = "https://admin:password@oursite.com/@api/users/=$user_id/properties/";
    $xml = new SimpleXMLElement($xmlString);

    function curl_fetch($url,$username,$password,$method='DELETE')
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
        return  curl_exec($ch);
    }

    print "The following properties have been removed: ";
    print "<br />";

    if(!count($xml->property)) die('No properties exist for this user');

    foreach($xml->property as $property) {
      $name = $property['name'];
      $name2=str_replace(array('@', '#'), array('%40', '%23'), $name);
      print $name2;
      print "<br />";
      curl_fetch($delete . $name2,'admin','password');
    }
    ?>

【问题讨论】:

    标签: php xml curl


    【解决方案1】:

    您正在以 GET 查询的形式访问该 URL。您确定进行删除类型的调用至少不需要 POST 吗?想想如果网络蜘蛛得到一个 url 列表并通过简单地索引它来无辜地攻击你的整个网站会发生什么混乱?

    我的错,没有注意到 DELETE 是 curl 函数中的默认方法。

    我建议从 curl 函数中回显完整的 URL,并验证它是否正确构建。我看不出代码有任何其他明显错误,所以我猜测 URL 不正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-15
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      相关资源
      最近更新 更多