I want to parse some information out of a html page.
Currently I solve the problem like this:
header("Content-type: text/plain");
$this->pageSource = file_get_contents ($this->page);
header("Content-type: text/html");
$this->page
is the url of the website.
This works fine on XAMPP, but when I upload my script on my webserver, I get the following error message:
Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0
So obviously I am not allowed to execute that function on my webserver.
So is there an equivalent function to solve my problem?
Actually the function file_get_contents
is not disabled,
but allow_url_fopen
is disabled
you can replace it with curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$this->pageSource = curl_exec($ch);
curl_close($ch);
However, if you server block outgoing traffic, curl
does not help too
cURL is the usual standard solution.
Use curl
and why do you need to change the header to plain text to retrieve data? This is not necessary if you are retrieving data.
if you have curl, use it it is great for this.
$urlx = 'http://yoururl';
$data="from=$from&to=$to&body=".urlencode($body)."&url=$url";
//set post parameters
$process = curl_init($urlx);
//init curl connection
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER,1);
curl_setopt($process,CURLOPT_CONNECTTIMEOUT,1);
$resp = curl_exec($process);
//your content
curl_close($process);