Jump to content

Recommended Posts

Ok i'm tring to include a file in a page, it's the simplist of things but it's not working... I don't know much PHP so sorry if I'm overlooking something obvious.

 

allow_url_include is set to On by the way

 

the code i've got is:

 

<?php

include ("http://www.myurl.com/test.html");

?>

 

Includes work fine with local files, I've asked someone at my hosting company and they say it should be working fine so I really just dunno what to do :(

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/
Share on other sites

IMO include/require should only be used for including PHP source code. For static content such as HTML you should use file_get_contents

 

Also instead of posting "its not working" can you explain what you actually mean by that. Like are you getting an error or blank page etc. If you're getting errors then post them here in full.

Sorry about the lack of specificness...

 

There's no error messages, the output stops where the included file should be. So the code is being read and when the include statement is read, it just stops.

 

I haven't come across file_get_contents before, I will try to use it and see what happens.

I've tried the single and double quotes and it doesn't seem to make any difference.

 

First I tried adding the code to enable error reporting, this didn't do anything, still just nothingness when the code starts.

 

Then I tried the collowing code:

 

$file = "test.html";

file_get_contents($file);

 

This didn't work at all which seems odd (the script just stops when it gets to that bit of code), maybe there's an error in the syntax, I've looked at some examples and followed them.

 

Any more help would be greatly appreciated, thank you

Ok i'm tring to include a file in a page, it's the simplist of things but it's not working... I don't know much PHP so sorry if I'm overlooking something obvious.

 

allow_url_include is set to On by the way

 

the code i've got is:

 

<?php

include ("http://www.myurl.com/test.html");

?>

 

Includes work fine with local files, I've asked someone at my hosting company and they say it should be working fine so I really just dunno what to do :(

 

Thanks

try this

<?php
if ($fh = fopen('http://www.myurl.com/test.html', 'r') ) {
    fpassthru($fh);
    fclose($fh);
}
?>

Ok thanks for the help, I've managed to get it working by simply using:

 

echo file_get_contents('http://www.url.com/file.html');

 

Not sure why include() wasn't getting the remote file... I'm running PHP 5.2.6 for anyone who's interested

 

Thanks again!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.