Welcome Guest, Not a member yet? Register   Sign In
CURL, open_basedir=/usr/local/lib/php:/tmp, and CI?
#1

[eluser]zimco[/eluser]
I wrote a CodeIgniter application that utilizes CURL and CURLOPT_FOLLOWLACTION and it works great on my localhost. However, when i move it up to the production server the open_basedir is set, but safe_mode is off, and i'm running into the error msg:
Code:
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /home/user/public_html/script.php on line...
After doing some googling on this subject, it was suggested that you move the part of the script that uses CURL into a shell script in the /tmp directory on the server and inside your web application call the shell script with this code:
Code:
$check = shell_exec('/tmp/script.php');

Can this be done within a codeigniter application? If so, any suggestions on how to rewrite the part of my code that uses CURL and put it into a shell script that could be called from within my CI app?

The two functions in my CI app that i'm trying to get to work look like this:

Code:
/*======================================================================*\
    Function:    _get($url,$refer='')
    Purpose:    Runs a GET through cURL
    Input:        
    Output:
    Access:        private
\*======================================================================*/    

    function _get($url,$refer='') {
        $Debug=true;
        $ch=0;
        $ch = curl_init($url) or die(curl_error());
        $mycookie_file="/tmp/cookie.txt";
        //$ckfile = tempnam ("/tmp", "CURLCOOKIE");
        
        // set a page referrer
        curl_setopt($ch, CURLOPT_REFERER, $refer);
        // set the url to fetch
        curl_setopt($ch, CURLOPT_URL,$url);
        // set the cookie in specified  file
        curl_setopt ($ch, CURLOPT_COOKIEJAR, $mycookie_file);
        curl_setopt($ch, CURLOPT_POST, 1);
        // return the value instead of printing the response to browser
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        // give me the headers
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch,CURLOPT_TIMEOUT,15);

        $data=curl_exec($ch) or die(curl_error());
        
        echo curl_error($ch);
        return $data;
        // remember to always close the session and free all resources
        curl_close($ch);
    }


/*======================================================================*\
    Function:    _post($url,$data,$refer)
    Purpose:    Runs a POST through cURL
    Input:        
    Output:
    Access:        private
\*======================================================================*/    

     function _post($url,$data,$refer, $mycookie_file) {
     //echo "DATA: ".'__EVENTTARGET='.$data['__EVENTTARGET'].'&__EVENTARGUMENT='.$data['__EVENTARGUMENT'].'&__VIEWSTATE='.$data['__VIEWSTATE'];
          $process = curl_init($url);
          
          curl_setopt($process, CURLOPT_REFERER, $refer);
          // Get cookie from our cookie file
          curl_setopt ($process, CURLOPT_COOKIEFILE, $mycookie_file);
          curl_setopt($process, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)");
          curl_setopt($process, CURLOPT_TIMEOUT, 15);
          curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
          curl_setopt($process, CURLOPT_POST, 1);
          curl_setopt($process, CURLOPT_POSTFIELDS,'__EVENTTARGET='.$data['__EVENTTARGET'].'&__EVENTARGUMENT='.$data['__EVENTARGUMENT'].'&__VIEWSTATE='.$data['__VIEWSTATE'].$data['my_vars']);
          
          $return = curl_exec($process);
      
          curl_close($process);
          
          return $return;
     }

I call these functions in my CI app like:
Code:
$page = $this->_get($my_url, $my_refer);
.
.
.
$next_page = $this->_post($post_url, $post_data, $my_refer, $mycookie_file);
I am not familiar with using shell and my feeble attempts like the following got me no where:
Code:
#!/usr/bin/php
<?php    
        $Debug=true;
        $ch=0;
        $ch = curl_init($url) or die(curl_error());
        $mycookie_file="/tmp/cookie.txt";
        //$ckfile = tempnam ("/tmp", "CURLCOOKIE");
        
        // set a page referrer
        curl_setopt($ch, CURLOPT_REFERER, $refer);
        // set the url to fetch
        curl_setopt($ch, CURLOPT_URL,$url);
        // set the cookie in specified  file
        curl_setopt ($ch, CURLOPT_COOKIEJAR, $mycookie_file);
        curl_setopt($ch, CURLOPT_POST, 1);
        // return the value instead of printing the response to browser
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        // give me the headers
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch,CURLOPT_TIMEOUT,15);

        $data=curl_exec($ch) or die(curl_error());
        
        echo curl_error($ch);
        return $data;
        // remember to always close the session and free all resources
        curl_close($ch);
?>
#2

[eluser]TheFuzzy0ne[/eluser]
Have you asked you're host if it's possible for either you are them to configure your vhost entry to remove that directive?
#3

[eluser]zimco[/eluser]
Here's what i've been told: it's a shared webserver and if you disable the open_basedir directive on the server all the directories on the server with a 777 permission are not safe and you're going to create some security issues.




Theme © iAndrew 2016 - Forum software by © MyBB