【发布时间】: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');
}
?>
【问题讨论】: