"curlopt_followlocation cannot be activated" Answer’s

0

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.
  }
Wednesday, March 31, 2021
 
TMichel
answered 10 Months ago
0

Set safe_mode = Off in your php.ini file (it's usually in /etc/ on the server). If that's already off, then look around for the open_basedir stuff in the php.ini file, and change it accordingly.

Basically, the follow location option has been disabled as a security measure, but PHP's built-in security features are usually more annoying than secure. In fact, safe_mode is deprecated in PHP 5.3.

Wednesday, June 9, 2021
 
BrunoRamalho
answered 8 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :