1
我在php中创建了一个用于捕获用户属性的脚本。php脚本中的ssl潜在问题
为了做到这一点,它需要调用api来获取这些属性。
我设定的网址是:
$url=("http://user:[email protected]/@api/users/=$user_id/properties");
然后使用的file_get_contents为XML。
当我只是在浏览器中输入这个URL,它工作正常。它立即为给定用户输出这些属性。但它看起来好像自动将其切换到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:[email protected]/@api/users/=$user_id/properties");
echo $url;
$xmlString=file_get_contents($url);
$delete = "http://user:[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,'user','pass');
}
感谢您的回复。所以我实际上已经在使用卷曲脚本。我编辑了原始文章,以便看到代码。你说我可以使用setopt,这应该工作? – Aaron 2010-10-15 14:27:37
它应该,试试看,我相信这是一个更快的方法来确定它是否有效。 – 2010-10-15 14:58:15
对不起,我想我问的原因是因为我没有看到任何不同。我将它添加到了curl_fetch函数的开头。它是否有可能与xmlString = file_get_contents($ url)有关,因为这是在curl之前完成的? – Aaron 2010-10-15 15:08:21