GoDaddy Hosting Tip – Using CURL On GoDaddy Shared Hosting

By  on  

I want to throw a quick tip out there to anyone that plans to use cURL on GoDaddy hosting servers. I've been developing a shopping cart and ported the site from my development server to the hosting server. I ran into a huge problem when trying to get the cart to connect to UPS for real-time shipping quotes. What was the problem? The connection between my PHP (GoDaddy Server) and the UPS server wasn't being made.

After a few lifetimes hours of searching, I found the answer. GoDaddy requires additional cURL code to use their proxy server. Below is their example of the code you'll need:

$url = 'https://www.paypal.com';
$ch = curl_init();
curl_setopt($ch,CURLOPT_VERBOSE,1);
//curl_setopt($ch,CURLOPT_HTTPPROXYTUNNEL,true);
curl_setopt($ch,CURLOPT_PROXYTYPE,CURLPROXY_HTTP);
curl_setopt($ch,CURLOPT_PROXY,'http://proxy.shr.secureserver.net:3128');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_TIMEOUT,120);
$result = curl_exec($ch);
curl_close($ch);

You can read more here. I know this isn't the usual poetry I post, but one goal with my blog is to save other developers time when possible.

Recent Features

  • By
    Chris Coyier’s Favorite CodePen Demos

    David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...

  • By
    Write Better JavaScript with Promises

    You've probably heard the talk around the water cooler about how promises are the future. All of the cool kids are using them, but you don't see what makes them so special. Can't you just use a callback? What's the big deal? In this article, we'll...

Incredible Demos

  • By
    Fade Images with MooTools LazyLoad

    I recently received an email from a MooTools developer asking a great question about my LazyLoad class: "I'm using your LazyLoad MooTools plugin (which is great, by the way). I have been trying to figure out how to modify it so that once an image scrolls into...

  • By
    Chris Coyier’s Favorite CodePen Demos II

    Hey everyone! Before we get started, I just want to say it's damn hard to pick this few favorites on CodePen. Not because, as a co-founder of CodePen, I feel like a dad picking which kid he likes best (RUDE). But because there is just so...

Discussion

  1. Roberto Flores

    Thanks. It solved my problem connecting to authorize.net.

  2. Chris

    Hi David,

    Thought you had save me an mess of heartache when I stumbled upon this post. However, it appears that GoDaddy have changed the way they do things as of 10th Sept 2008.

    see http://help.godaddy.com/article/4764

    The following code now works fine….. on initial testing anyway.

    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " )); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    

    But thanks for the thought.
    Chris

  3. Thanks! I was looking for a solution to this all last night. Plugged in the code and it worked! Thanks again.

  4. Dear lord! I spent an hour on the phone with GoDaddy and they seem to have no clue that this code exists. Thank you!

  5. juan

    @Chris: k tal fijate que tengo este codigo pero no me jala

    	$query_vals = array(
    		'cIdioma' => 'Esp',
    	    'cCodPosOri' => $cpOrigen,
    	    'cCodPosDes' => $cpDestino,
    	    'cTipoEnvio' => $Tipo,
    	    'nPeso' => $Peso,
    	    'nAlto' => $Alto,
    	    'nLargo' => $Largo,
    	    'nAncho' => $Ancho,
    	    'submit' => 'Calcular'
    	);
    	$request = '';
    
    	// Generate the POST string
    	foreach($query_vals as $key => $value) {
    	    $request .= $key.'='.urlencode($value).'&';
    	}
         
    
    	// Chop of the trailing ampersand
    	$request = rtrim($request, '&');
    
    
    
    $url="http://tarifas";
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    
  6. juan

    @Chris: me dices que no reconoce el array

  7. R Zaman

    hello friends,

    i was trying to send a xml file from godaddy server to another ftp server using cURL.

    But, it’s not working, can anyone help me on this issue.

    Below is my code:

    please anyone help me.

    my email id: rzrokon@gmail.com

  8. R Zaman

    Hello friends,

    I was trying to send a xml file from godaddy server to another ftp server using cURL. It’s working on other server.

    But, it’s not working on godaddy, can anyone help me on this issue.

    Below is my code:

    please anyone help me.

    my email id: rzrokon@gmail.com

  9. it works like a charm

  10. dominio público

    Turning off VERIFY_PEER is not a good solution. You should be providing a CA chain so your payments don’t get man-in-the-middled.

  11. Hi,
    i read your code i tried it but its shown error what should exatly write for my host to connect to my server ?
    there is my curl :

     'Error', 'Error' => curl_error($curl)); 
        else if (empty($response)) $obj = (object) array('Result' => 'Error', 'Error' => 'Connection failed'); 
        else $obj = json_decode($response);
        curl_close($curl);
        return $obj;
      }
    
    
    ?>
    

    i did as you wrote with the proxy but the error shown that its refused to connect to the curl

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!