PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi there. I'm still step-by-step learning PHP. I now have a grasp on how to use include to grab external HTML files and include them in my present page. I would like to know how to use include to grab an external file (ie - a file that I have on a different free web server). Is that possible? Here's what I have right now:
Actual Code:
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
That line in itself IS a link to an external stylesheet...
Including PHP files from other servers is bad practice.
That being said, if you MUST do it for some reason look into file-get-contents() and eval() - but I would strongly encourage you to avoid this technique.
mibocote wrote:Do you want the remote page to return your stylesheet, or do you want it to return the html to your stylesheet?
I want it to return a reference to my stylesheet. To where in all the pages I create, I use the reference to this file and this file refers to whatever my current stylesheet is.
That line in itself IS a link to an external stylesheet...
Including PHP files from other servers is bad practice.
That being said, if you MUST do it for some reason look into file-get-contents() and eval() - but I would strongly encourage you to avoid this technique.
I guess I don't have to refer to it on a different server. I think my point is that I want the ability to do so. However, could you share with me why it's bad practice?
Mark
EDIT: Also, I know that line you quotes was a reference to a stylesheet. That's what comes up through the included file. I wanted to know how to reference an absolute external url with PHP's include. I will, however, look into the two commands you suggested. Thank you.
Kieran Huggins wrote:
That being said, if you MUST do it for some reason look into file-get-contents() and eval() - but I would strongly encourage you to avoid this technique.
Actually, you can use include on files from remote servers, provided the allow_url_fopen is set accordingly. Problem is, you will just be getting the output of the script (I assume you want code to be included, in which case simply rename the file to have a non *.php style fileneame (or other depending on server configuration)).
MarkT78 wrote:
I guess I don't have to refer to it on a different server. I think my point is that I want the ability to do so. However, could you share with me why it's bad practice?
It is considered bad practice because anytime you access something you have to consider how secure it is. Do you know for sure that the DNS entry is pointing to the correct IP and not another server that might have a page injected that would cause harm to your script, or that that website has not been hacked?
MarkT78 wrote:
And how is this done? Just typing in the url? If so, how do I check to see if allow_url_fopen is available on my own system (PHP5 with Apache 2.2)?
include 'http://example.com/includedscript.php'; // This will return to your script the output of that script
include 'http://example.com/includedscript.inc'; // On most default configurations this will add the code in like a local include would
I do recommend against this.
Edit:
allow_url_fopen is part of your PHP configuration (php.ini)
MarkT78 wrote:
I guess I don't have to refer to it on a different server. I think my point is that I want the ability to do so. However, could you share with me why it's bad practice?
It is considered bad practice because anytime you access something you have to consider how secure it is. Do you know for sure that the DNS entry is pointing to the correct IP and not another server that might have a page injected that would cause harm to your script, or that that website has not been hacked?
Kieran Huggins wrote:That being said, if you MUST do it for some reason look into file-get-contents() and eval() - but I would strongly encourage you to avoid this technique.
Actually, you can use include on files from remote servers, provided the allow_url_fopen is set accordingly. Problem is, you will just be getting the output of the script (I assume you want code to be included, in which case simply rename the file to have a non *.php style fileneame (or other depending on server configuration)).
Doh! Forgot that point... nice catch mibocote!
To add to the security considerations:
If you don't own / exclusively manage both domains, you can only trust the code to the extent that you can personally trust whoever has access to it in addition to the security of the system, and the transmission.
If you do own / exclusively manage both domains, why not just copy the files once and save the traffic & load time overhead on each page?