tags:

views:

30

answers:

1

I've created a php script that will allow the removal of user properties. The script first finds all properties associated with a user and then loops to remove all of them.

When I run this for a certain user, it gets down to the foreach loop and it prints out all the the properties ($name2) but it seems to get stuck on the curl_fetch part. When I then try to pull the properties, they still exist for the user. Any ideas why this is happening? The code is below for you to take a look. Thanks in advance.

 <?php

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

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

    $url=("https://admin:[email protected]/@api/users/=$user_id/properties");
    $xmlString=file_get_contents($url);

    $delete = "https://admin:[email protected]/@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');
    }
    ?>
A: 

You're hitting that URL as a GET query. Are you sure doing a delete-type call wouldn't at least require a POST? Think of the chaos that would ensue if a web spider got a list of urls and innocently nuked your entire site by simply indexing it?

My bad, didn't notice that DELETE was the default method in your curl function.

I'd suggest echoing out the complete URL from within the curl function, and verifying that it is being built properly. I can't see anything else obviously wrong with the code, so I'm guessing the URL's incorrect.

Marc B