php - php 脚本中 ssl 的潜在问题

标签 php ssl https

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

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

我设置的url是:

 $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');
}

最佳答案

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

关于php - php 脚本中 ssl 的潜在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3942417/

相关文章:

iphone - 如何在 iphone 中使用 ssl 证书和 HTTPS 实现

ssl - 通过 SSL 与 Meteor 应用程序建立 DDP 连接

google-app-engine - GAE SSL 证书要求

ssl - Jetty 9 无法使用 OpenSSL 生成的自签名证书

apache - http 或 https 中的不同 htaccess

javascript - 安排 PHP 文件运行

php - 从 CakePHP 组件到达 CakeRequest 对象

php - 如何从 MySQL 大表中删除列

PHP - 尽管打印文本,但为什么不打印变量?

c# - C# (C Sharp) 中的 Apache HTTP 服务器实现