Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file content via PHP cURL [closed]

Tags:

php

curl

I have an website. Let's call it http://www.domain.com. Now, on this domain.com I want to display the file contents of http://www.adserversite.com/ads.php. How can I do that with cURL or another method? I don't want to use iframe.

Thanks

like image 657
Ganikkost Avatar asked Oct 08 '12 12:10

Ganikkost


2 Answers

You can use file_get_contents as Petr says, but you need to activate allow_url_fopen in your php.ini and perhaps your hosting do not allow you to change this.

If you prefer to use CURL instead of file_get_contents, try this code:

<?php
$url = 'http://www.adserversite.com/ads.php';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
like image 51
m4t1t0 Avatar answered Oct 06 '22 01:10

m4t1t0


echo file_get_contents('http://www.adserversite.com/ads.php');

Who needs curl for this simple task?

like image 43
Petr Avatar answered Oct 06 '22 00:10

Petr