CURL working from localhost but not on live site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pranavkavi
Forum Newbie
Posts: 4
Joined: Sun May 09, 2010 2:07 am

CURL working from localhost but not on live site

Post by pranavkavi »

I have a CURL code that fetches some XML content from a remote server. I get the expected output on my localhost (XAMPP on windows). But from the live site(hosted on Linux), I get the CURL error:'couldn't connect to host'.

Code: Select all

	function DownloadUrl($Url, $p){
	 
		// is curl installed?
		if (!function_exists('curl_init')){ 
			die('CURL is not installed!');
		}

       // create curl resource
        $ch = curl_init();

        // set url
        curl_setopt($ch, CURLOPT_URL, $Url);

	   curl_setopt ($ch, CURLOPT_POSTFIELDS, $p);
	   curl_setopt ($ch, CURLOPT_POST, 1);
        //return the transfer as a string
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        // $output contains the output string
        $output = curl_exec($ch);
        
	   if($output === false)
		   echo 'Curl error: ' . curl_error($ch);
	   else
    		print $output;
        // close curl resource to free up system resources
        curl_close($ch);          
	}
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: CURL working from localhost but not on live site

Post by pickle »

Check the remote host - maybe there are access restrictions.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply