【问题标题】:CURLOPT_FOLLOWLOCATION cannot be activatedCURLOPT_FOLLOWLOCATION 无法激活
【发布时间】:2011-06-15 04:14:48
【问题描述】:

我有一些卷发问题,我不知道如何解决。

这个想法是获取用户的用户名和密码并将其发布到外部网页。

代码如下:

$ch = curl_init(); 
  curl_setopt( $ch, CURLOPT_URL, "https://sso.uc.cl/cas/login?service=https://portaluc.puc.cl/uPortal/Login"); // URL to post 
  curl_setopt ($ch, CURLOPT_POST, 1);
  curl_setopt ($ch, CURLOPT_POSTFIELDS,         "username=$usuario&password=$pw");
  curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
  $result = curl_exec( $ch ); // runs the post 
  curl_close($ch);
  echo "Reply Response: " . $result; // echo reply response 

这是错误:

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/th000862/public_html/encuesta/login2.php on line 10

出现该错误后,用户未登录到外部网页。

【问题讨论】:

  • 如果 curl 变通方法不起作用,请尝试 PEAR Http_Request2 或 Zend/Horde 或其他 HTTP 实用程序实现。

标签: php curl


【解决方案1】:

该错误意味着您的 PHP 配置禁止您跟随该位置。有几种方法可以解决此问题,而无需按照@mario 的建议安装其他库。

  • 如果您拥有服务器或拥有 root 访问权限,您可以更改 php.ini 文件以禁用“safe_mode”。
  • 您还可以在文档根目录中创建一个 .htaccess 文件,其中包含 php_value safe_mode off
  • 您可以在 PHP 文件中添加 ini_set('safe_mode', false);

如果上述方法都不起作用,您也可以按照以下方式进行操作:

$ch = curl_init('https://sso.uc.cl/cas/login?service=https://portaluc.puc.cl/uPortal/Login');

curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=' . urlencode($usuario) . '&password=' . urlencode($pw));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

$result = curl_exec($ch);

curl_close($ch);

// Look to see if there's a location header.
if ( ! empty($result) )
  if ( preg_match('/Location: (.+)/i', $result, $matches) )
  {
    // $matches[1] will contain the URL.
    // Perform another cURL request here to retrieve the content.
  }

【讨论】:

    【解决方案2】:

    你也需要这样做: 要使用 https 协议访问页面,您需要将 CURLOPT_SSL_VERIFYPEER 更改为 false。

    试试这个:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    

    【讨论】:

      猜你喜欢
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-20
      • 2017-11-13
      • 2019-06-28
      • 1970-01-01
      相关资源
      最近更新 更多