无法激活CURLOPT_FOLLOWLOCATION [英] CURLOPT_FOLLOWLOCATION cannot be activated

查看:173
本文介绍了无法激活CURLOPT_FOLLOWLOCATION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



以下是代码

  $ 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); //运行后
curl_close($ ch);
echo回复回复:。 $ result; // echo reply response

这里是错误:

警告:curl_setopt()[function.curl-setopt]:如果启用了safe_mode或在/ home / set_init中设置了open_basedir,则不能激活CURLOPT_FOLLOWLOCATION; th000862 / public_html / encuesta / login2.php on line 10

出现此错误后,

解决方案

这个错误表示您的PHP配置禁止您跟踪该位置。有几种方法可以解决问题,而不需要像@mario所建议的那样安装其他库。




  • 如果您拥有服务器或root访问,您可以更改php.ini文件以禁用safe_mode。

  • 您也可以在文档根目录中创建一个.htaccess文件 php_value safe_mode off in it。

  • 您可以在 ini_set('safe_mode',false); 您的PHP文件。



如果上述操作都无效,您也可以按照以下方式执行:

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

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);

//看看是否有一个位置头。
if(!empty($ result))
if(preg_match('/ Location:(。+)/ i',$ result,$ matches))
{
/ / $ matches [1]将包含该URL。
//在这里执行另一个cURL请求来检索内容。
}


im having some problems with curls and i dont know how to solve them.

the idea is to get a user's username and pw and post it into an external webpage.

Here is the code:

$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 

here is the error:

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

After that error, the user is not logged in into the external webpage.

解决方案

That error means that your PHP configuration is prohibiting you from following the location. There are a few ways you could work around the problem without installing additional libraries as suggested by @mario.

  • If you own the server or have root access, you could change the php.ini file to disable "safe_mode".
  • You could also create a .htaccess file in your document root with php_value safe_mode off in it.
  • You may be able to add ini_set('safe_mode', false); in your PHP file.

If none of the above works, you could also do something along these lines:

$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.
  }

这篇关于无法激活CURLOPT_FOLLOWLOCATION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆