sgt_fireman Posted July 29, 2012 Share Posted July 29, 2012 Hey guys, So I need to try and create an equivalent of doing, <? include ("http://www.example.com/example.php")?> Now I know this isn't possible to just use the code above (At least I've been told) So does anyone know any alternatives? Thanks very much in advanced guys. Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/ Share on other sites More sharing options...
Pikachu2000 Posted July 29, 2012 Share Posted July 29, 2012 Any output of a php file from a properly configured web server will only be the rendered output, not php code. What are you trying to acomplish? Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365172 Share on other sites More sharing options...
Christian F. Posted July 29, 2012 Share Posted July 29, 2012 Do you want to execute the PHP code in that file, or just get the resulting HTML? If it's the former: You cannot. At least not without editing the script to print out the actual PHP code, or changing it to a pure text file. In any case this is an extremely bad idea, as you give away complete control to your server. Not to mention the latency increase.. If it's the latter, I recommend a look at cURL. Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365173 Share on other sites More sharing options...
sgt_fireman Posted July 29, 2012 Author Share Posted July 29, 2012 I was trying to get it to run the code in the php file :/ does this mean it's not possible? Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365175 Share on other sites More sharing options...
Christian F. Posted July 29, 2012 Share Posted July 29, 2012 As it's written now, yes. This is because you're making a HTTP call to the web server, which interprets the PHP code and sends out the resulting HTML. Just like a web browser. You're much better off copying said file to your local server, and including it properly. That way you don't have to wait for the HTTP response, which would increase the include time from nano seconds to milliseconds. Several thousand times slower, in other words. Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365176 Share on other sites More sharing options...
sgt_fireman Posted July 29, 2012 Author Share Posted July 29, 2012 Additional information: I own the server that holds the file to include, and the file is basically designed to be ran on other pages... is there some way of enabling the one file to be ran on other servers? If you haven't guessed by the way, I'm clueless on this topic. Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365177 Share on other sites More sharing options...
sgt_fireman Posted July 29, 2012 Author Share Posted July 29, 2012 Okay thanks christian, on another note, as I said on the OP, how exactly would I include another servers file if it were to be the method I chose? Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365178 Share on other sites More sharing options...
Christian F. Posted July 29, 2012 Share Posted July 29, 2012 Easiest way would be to save it as a .txt file, and include it as such: include ("http://www.server.invalid/source.txt"); That's a quick and dirty way of doing it, and perfect if you're not going to run it on the local server. If you want to make sure it's always updated, and can be run on the local server as well, then you need to do something like this: // At the top of "source.php" if (isset ($_GET['show_source']) && $_GET['show_source'] == 1) { die (file_get_contents (__FILE__)); } And then include it like this: include ("http://www.server.invalid/source.php?show_source=1"); However, you should note that if you do it like this then everyone will be able to open it up and read the source code as well. So only do this if you're absolutely certain that: [*]Latency times have no meaning, at all. [*]It is 100% safe to show the source code to the entire world. In the vast majority of times, you'll find that both of these will indeed make it ill adviced. Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365180 Share on other sites More sharing options...
sgt_fireman Posted July 29, 2012 Author Share Posted July 29, 2012 Okay thank-you very much! Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365183 Share on other sites More sharing options...
Christian F. Posted July 29, 2012 Share Posted July 29, 2012 You're welcome. Quote Link to comment https://forums.phpfreaks.com/topic/266399-include-another-servers-file/#findComment-1365185 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.