geenee Posted November 16, 2008 Share Posted November 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/ Share on other sites More sharing options...
Andy82 Posted November 16, 2008 Share Posted November 16, 2008 Hey, Im a newbie too. The PHP Manual show here http://uk2.php.net/include/ in Example 3 that you should be using single quotes. // Works. include 'http://www.example.com/file.php?foo=1&bar=2'; Andy Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/#findComment-691359 Share on other sites More sharing options...
wildteen88 Posted November 16, 2008 Share Posted November 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/#findComment-691375 Share on other sites More sharing options...
geenee Posted November 16, 2008 Author Share Posted November 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/#findComment-691414 Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2008 Share Posted November 16, 2008 You are probably getting a fatal runtime error. Add the following two lines immediately after your first opening <?php tag - ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/#findComment-691427 Share on other sites More sharing options...
geenee Posted November 16, 2008 Author Share Posted November 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/#findComment-691681 Share on other sites More sharing options...
wildteen88 Posted November 17, 2008 Share Posted November 17, 2008 Your using file_get_contents incorrectly. Your code should be $file = "test.html"; echo file_get_contents($file); Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/#findComment-692162 Share on other sites More sharing options...
nicob Posted November 17, 2008 Share Posted November 17, 2008 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/#findComment-692225 Share on other sites More sharing options...
geenee Posted November 17, 2008 Author Share Posted November 17, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/132945-including-a-remote-file-not-working/#findComment-692234 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.