CURLOPT_FOLLOWLOCATION error

Sync Blizzards' Armory data with WoWRoster (addon depreciated no longer works see ApiSync)

Moderators: Ulminia, poetter

CURLOPT_FOLLOWLOCATION error

Postby Ulminia » Thu Dec 13, 2007 6:20 am

this is what i found online

If you are trying to use CURLOPT_FOLLOWLOCATION and you get this warning:
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set...

then you will want to read http://www.php.net/ChangeLog-4.php which says "Disabled CURLOPT_FOLLOWLOCATION in curl when open_basedir or safe_mode are enabled." as of PHP 4.4.4/5.1.5. This is due to the fact that curl is not part of PHP and doesn't know the values of open_basedir or safe_mode, so you could comprimise your webserver operating in safe_mode by redirecting (using header('Location: ...')) to "file://" urls, which curl would have gladly retrieved.

Until the curl extension is changed in PHP or curl (if it ever will) to deal with "Location:" headers, here is a far from perfect remake of the curl_exec function that I am using.

Since there's no curl_getopt function equivalent, you'll have to tweak the function to make it work for your specific use. As it is here, it returns the body of the response and not the header. It also doesn't deal with redirection urls with username and passwords in them.
Code: Select all

<?php
    
function curl_redir_exec($ch)
    {
        static 
$curl_loops 0;
        static 
$curl_max_loops 20;
        if (
$curl_loops++ >= $curl_max_loops)
        {
            
$curl_loops 0;
            return 
FALSE;
        }
        
curl_setopt($chCURLOPT_HEADERtrue);
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
$data curl_exec($ch);
        list(
$header$data) = explode("\n\n"$data2);
        
$http_code curl_getinfo($chCURLINFO_HTTP_CODE);
        if (
$http_code == 301 || $http_code == 302)
        {
            
$matches = array();
            
preg_match('/Location:(.*?)\n/'$header$matches);
            
$url = @parse_url(trim(array_pop($matches)));
            if (!
$url)
            {
                
//couldn't process the url to redirect to
                
$curl_loops 0;
                return 
$data;
            }
            
$last_url parse_url(curl_getinfo($chCURLINFO_EFFECTIVE_URL));
            if (!
$url['scheme'])
                
$url['scheme'] = $last_url['scheme'];
            if (!
$url['host'])
                
$url['host'] = $last_url['host'];
            if (!
$url['path'])
                
$url['path'] = $last_url['path'];
            
$new_url $url['scheme'] . '://' $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');
            
curl_setopt($chCURLOPT_URL$new_url);
            
debug('Redirecting to'$new_url);
            return 
curl_redir_exec($ch);
        } else {
            
$curl_loops=0;
            return 
$data;
        }
    }
?>
Ulminia of Zangarmarsh
Zonous of Zangarmarsh
Author of Roster Gallery
WoWRoster-Profiler Redesigner
User avatar
Ulminia
WoWRoster.net Dev Team
WoWRoster.net Dev Team
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 1223
Joined: Tue Jul 04, 2006 4:41 pm
Location: New Brunswick, Canada
Realm: Zangarmarsh (PvE) - US
gmail/gtalk: ulminia@gmail.com

CURLOPT_FOLLOWLOCATION error

Postby poetter » Thu Dec 13, 2007 9:16 am

Hmm, sounds interesting. I tried to adapt your code. The result is this:

Code: Select all
--- C:/Dokumente und Einstellungen/Daniel/Lokale Einstellungen/Temp/functions.lib.php-revBASE.svn000.tmp.php   Thu Dec 13 01:12:18 2007
+++ D:/xampp/roster.com/htdocs/lib/functions.lib.php   Thu Dec 13 01:10:42 2007
@@ -1157,7 +1159,7 @@
 
       curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+      curl_setopt($ch, CURLOPT_HEADER, true);
       if( $user_agent )
       {
          curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
@@ -1170,17 +1172,32 @@
          trigger_error('UrlGrabber Error [CURL]: ' . curl_error($ch), E_USER_WARNING);
          return false;
       }
-      $lastUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
+
+        list($header, $data) = explode("\n\n", $contents, 2);
+        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+      curl_close($ch);
+        if ($http_code == 301 || $http_code == 302)
+        {
+            $matches = array();
+            preg_match('/Location:(.*?)\n/', $header, $matches);
+            $redirect = @parse_url(trim(array_pop($matches)));
+            if (!$redirect)
+            {
+                //couldn't process the url to redirect to
+                return $data;
+            }
+
       $tmp;
-      if( preg_match('/(?:jsessionid=)(.+)?\?/', $lastUrl, $tmp) )
+         if( preg_match('/^(?:Set-Cookie: JSESSIONID=)(.+)?\;/', $header, $tmp) )
       {
          $roster->cache->put($tmp[1], $cache_tag);
       }
 
-
-      curl_close($ch);
-
-      return $contents;
+            return urlgrabber( $redirect, $timeout, $user_agent, $loopcount );
+        } else {
+            $curl_loops=0;
+            return $data;
+        }
    }
    elseif( preg_match('/\bhttps?:\/\/([-A-Z0-9.]+):?(\d+)?(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\?[-A-Z0-9+&@#\/%=~_|!:,.;]*)?/i', $url, $matches) )
    {


Can someone please try this patch and let me know how its doing?
Image
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

CURLOPT_FOLLOWLOCATION error

Postby Ulminia » Thu Dec 13, 2007 10:22 am

still getten error

lib/functions.lib.php
Warning line 1160: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set
Roster Warning line 1166: UrlGrabber Error [CURL]:
lib/armory.class.php
Roster Notice line 249: RosterArmory:: Failed to fetch http://www.wowarmory.com/character-shee ... &locale=en
addons/armorysync/inc/armorysync.class.php
Warning line 850: array_keys() [function.array-keys]: The first argument should be an array
Warning line 851: Invalid argument supplied for foreach()
Notice line 844: Undefined offset: 0
Ulminia of Zangarmarsh
Zonous of Zangarmarsh
Author of Roster Gallery
WoWRoster-Profiler Redesigner
User avatar
Ulminia
WoWRoster.net Dev Team
WoWRoster.net Dev Team
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 1223
Joined: Tue Jul 04, 2006 4:41 pm
Location: New Brunswick, Canada
Realm: Zangarmarsh (PvE) - US
gmail/gtalk: ulminia@gmail.com

Re: CURLOPT_FOLLOWLOCATION error

Postby tuigii » Thu Dec 13, 2007 10:31 am

I think you'll be having a hard time coding arround the :
safe_mode On
open_basedir On
issue.

The Roster Diag is telling treu when it wants them both set to Off.

The way curl works is for some web hosters a near security 'limit' that they don't like.

Live will be easier when you work with a
safe_mode Off
open_basedir Off

Really.
User avatar
tuigii
WR.net Master
WR.net Master
 
Posts: 891
Joined: Wed Dec 27, 2006 12:57 pm
Location: Somewhere in the South Ouest of France

CURLOPT_FOLLOWLOCATION error

Postby Ulminia » Thu Dec 13, 2007 10:41 am

safemode is off its open_basedir and the only reasion its on is most webhosts use it for defining multiple directories... ial talk to my host see what i can doo
Ulminia of Zangarmarsh
Zonous of Zangarmarsh
Author of Roster Gallery
WoWRoster-Profiler Redesigner
User avatar
Ulminia
WoWRoster.net Dev Team
WoWRoster.net Dev Team
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 1223
Joined: Tue Jul 04, 2006 4:41 pm
Location: New Brunswick, Canada
Realm: Zangarmarsh (PvE) - US
gmail/gtalk: ulminia@gmail.com

CURLOPT_FOLLOWLOCATION error

Postby poetter » Thu Dec 13, 2007 6:40 pm

Help me to understand that.

We left out this line:
Code: Select all
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

And your are still getting an error?

If so may be it is on by default so try
Code: Select all
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
Image
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

CURLOPT_FOLLOWLOCATION error

Postby Ulminia » Thu Dec 13, 2007 10:13 pm

tryed that nothing same stuff its not getten the stuff from the armory ... what ever happened to just phasing the xml data like relmstatus ... and my host witch previous versions of armory synch worked on will not remove the opendir for me because it opend a secourity risk so i dono
Ulminia of Zangarmarsh
Zonous of Zangarmarsh
Author of Roster Gallery
WoWRoster-Profiler Redesigner
User avatar
Ulminia
WoWRoster.net Dev Team
WoWRoster.net Dev Team
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 1223
Joined: Tue Jul 04, 2006 4:41 pm
Location: New Brunswick, Canada
Realm: Zangarmarsh (PvE) - US
gmail/gtalk: ulminia@gmail.com

CURLOPT_FOLLOWLOCATION error

Postby Equisetum » Fri Dec 14, 2007 10:08 am

I'm having this issue as well, and couldn't find an answer yet in the forums. If it's somewhere that I missed or this is a totally n00b question please forgive me!

I asked my webhost to set open_basedir off, and of course they said no, but that they can add secondary paths. What paths would need to be set if I were to take them up on this?

Thanks so much! I can almost taste victory getting this awesome addon to work!
Image
User avatar
Equisetum
WR.net Apprentice
WR.net Apprentice
 
Posts: 65
Joined: Mon Jul 24, 2006 6:44 am

CURLOPT_FOLLOWLOCATION error

Postby poetter » Fri Dec 14, 2007 10:11 am

Help is on the way. See here
Image
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg

CURLOPT_FOLLOWLOCATION error

Postby Equisetum » Fri Dec 14, 2007 10:29 am

Thanks for responding! I read that post before, and even tried the lib, but to no avail... I'm, still getting the same error. Shall I post the error in the other thread?

Thanks for your patience. :)
Last edited by Equisetum on Fri Dec 14, 2007 10:31 am, edited 1 time in total.
Image
User avatar
Equisetum
WR.net Apprentice
WR.net Apprentice
 
Posts: 65
Joined: Mon Jul 24, 2006 6:44 am

CURLOPT_FOLLOWLOCATION error

Postby poetter » Fri Dec 14, 2007 11:37 am

Yes please
Image
User avatar
poetter
Roster AddOn Dev
Roster AddOn Dev
 
Posts: 462
Joined: Sat Jun 30, 2007 9:41 pm
Location: Germany/Hamburg


Return to ArmorySync - Depreciated

Who is online

Users browsing this forum: No registered users and 1 guest

cron