Forum Moderators: coopster

Message Too Old, No Replies

Include a php file that is online - not local

         

one_mind

5:20 pm on Aug 3, 2006 (gmt 0)

10+ Year Member



Hi,

Someone asked me to include one of their php files in my code that is hosted on their server. I have done this like so:

include("http://www.somesite.com/level2/includes.php");

$info = return_user_info($_COOKIE["provident_email"]);

echo $info['Last Name'];

But i get this error: Fatal error: Call to undefined function return_user_info()

Is this even possible? Or do i need to store that include.php file locally?

Thanks

[edited by: dreamcatcher at 6:38 pm (utc) on Aug. 3, 2006]
[edit reason]
[1][edit reason] Generalized url. See TOS [webmasterworld.com] [/edit]
[/edit][/1]

coopster

9:06 pm on Aug 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



including a file in that manner is asking your friend's server to fetch the request, process any php, and return the parsed result ... not raw PHP code as you expect.

Personally, I would get a copy and move it to your local server. Are there was to get the page in it's raw state? Probably, but do you really want to be doing that? You are basically asking that page to run whatever it would like on your server at that point. Not saying your friend might get malicious, but what if his server was compromised? Now you are too.

one_mind

2:28 am on Aug 4, 2006 (gmt 0)

10+ Year Member



Hi Coopster,

Its just that i am programming a script for him that will eventually be run on his server but while i'm developing i need his functions.

So is there a way to include it in my script without getting the file?

So far all calls to functions in the online file are unrecognized.

Cheers

coopster

1:58 pm on Aug 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'd get the file instead of jumping through hoops. But, if you must ... have him put a text version of the file somewhere where you can retrieve it publicly via an http GET request, read that file into a string (I would use file_get_contents() [php.net] as it will do both in one step for you. Then, you need to eval() [php.net] that string where ever you need to include it in your code.

Like I said though, this is an extremely insecure practice and I do not recommend it by any means.

wsmeyer

2:46 pm on Aug 4, 2006 (gmt 0)

10+ Year Member



What about just changing the file extension to .txt I believe that if it is being used as an included file on both sites this will work.

William.

coopster

4:10 pm on Aug 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, you are correct. PHP will parse it anyway, no need to eval() the string. Just include it:
include('http://example.com/included.txt');

mcavic

4:15 pm on Aug 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this is an extremely insecure practice

Yes, for what you're trying to do, it's probably okay, but it's a dangerous feature. I'm going to see if I can disable it on my servers without breaking any of my code.

one_mind

3:23 pm on Aug 7, 2006 (gmt 0)

10+ Year Member



cool, thanks guys.