matthias
matthias

Reputation: 2062

load https website with php

Hi I have the following problem,

I want to laod a website with php. I used CURL, but on my server I have open_basedir set.

So, I get the following error message:

CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in

Code is:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$store = curl_exec ($ch);
$error = curl_error ($ch);
return $store;

Is there an alternative way to load a website using php ?!

Thanks

Upvotes: 1

Views: 2608

Answers (1)

Cyclonecode
Cyclonecode

Reputation: 30131

You can try to get the content of the website using file_get_contents():

 $content = file_get_contents('http://www.example.com/');

 // to specify http headers like `User-Agent`,
 // you could create a context like so:
 $options = array(
   'http' => array(
      'method' => "GET",
      'header' => "User-Agent: PHP\r\n"
   )
 );
 // create context
 $context = stream_context_create($options);
 // open file with the above http headers
 $content = file_get_contents('http://www.example.com/', false, $context);

Upvotes: 2

Related Questions