Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including remote HTML file

Tags:

php

I'm working on a project and I want to include an HTML script which will hosted on Pastebin.

Something like:

include 'http://pastebin.com/raw/testiungshdhd';    

I tried

fgets(fopen('http://pastebin.com/raw/asdasddaqwe', 'r'));   

But negative.

like image 823
Aaron Alfonso Avatar asked Apr 02 '26 09:04

Aaron Alfonso


2 Answers

First you need to enable setting php.ini file as:-

allow_url_include=On

Then there are couple of possible ways to achieve it:

Method 1:

<?php 
    include("http://pastebin.com/raw/asdasddaqwe"); 
?>

Method 2:

<?php 
    echo file_get_contents("http://pastebin.com/raw/asdasddaqwe");
?>

DO this only if you trust remote source file which you are trying to include.

like image 137
Anik Avatar answered Apr 03 '26 23:04

Anik


Try cURL:

http://php.net/manual/en/book.curl.php

Basic example:

$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);

Ref: http://php.net/manual/en/curl.examples-basic.php

like image 29
RaV Avatar answered Apr 03 '26 21:04

RaV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!