我在php中创建了一个脚本,用于捕获用户的属性。
为了做到这一点,需要调用api来获取这些属性。
我设置的网址是:
$url=("http://user:pass@oursite.com/@api/users/=$user_id/properties");
然后使用file_get_contents作为xml。
当我在浏览器中输入此网址时,它可以正常工作。它会立即为给定用户输出这些属性。但它看起来好像会自动将其切换为https。有没有什么需要做的,所以这可以在使用PHP时工作?
代码:
<?php
$user=$_GET['userid'];
$user_id=str_replace(array('@', '#'), array('%40', '%23'), $user);
print "User-id: $user";
print "<br /><br />";
$url=("http://user:admin@oursite.com/@api/users/=$user_id/properties");
echo $url;
$xmlString=file_get_contents($url);
$delete = "http://user:admin@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,'user','pass');
}