【问题标题】:Potential issue with ssl in php scriptphp 脚本中 ssl 的潜在问题
【发布时间】:2010-10-15 12:58:15
【问题描述】:

我在 php 中创建了一个脚本,用于捕获用户的属性。

为此,需要调用api来获取这些属性。

我设置的网址是:

 $url=("http://user:pass@oursite.com/@api/users/=$user_id/properties");

然后对 xml 使用 file_get_contents。

当我简单地在浏览器中输入这个 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: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');
}

【问题讨论】:

    标签: php ssl https


    【解决方案1】:

    您可以使用curlcurl_setopt,它允许您将CURLOPT_FOLLOWLOCATION 设置为true,这应该遵循任何重定向并从结束页面返回输出。

    【讨论】:

    • 感谢您的回复。所以我实际上已经在使用 curl 脚本了。我编辑了原始帖子,以便您可以看到代码。你是说我可以使用 setopt,这应该可以吗?
    • 应该,试一试看看,我相信这是一种更快的方法来确定它是否有效。
    • 对不起,我想我问的原因是因为我没有看到任何不同之处。我将它添加到 curl_fetch 函数的开头。是否有可能与 xmlString=file_get_contents($url) 相关,因为这是在 curl 之前完成的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    相关资源
    最近更新 更多