简体   繁体   中英

PHP include link to online file

Can I use include (or something similar) to get functions (or something else) from an online file?

Something like this:

include 'http://stackoverflow.com/questions/ask.php';

Simple Answer: No

Elaborating: If you use http or https inside your file path, you are literally telling your code to include a file that is on the internet and to use the HTTP / HTTPS protocol in that process.

As you probably know, php code is executed on the server and is never displayed to users online, but rather the output of the php is displayed.

For that reason, you won't be able to gain access to your php functions while being a user from online (because that is how you will be perceived with the previous method) .

What you should do is either use relative paths or absolute paths to include php scripts with functions on the same server . Here is some php documentation if you want to read a bit more on how to format the path: PHP DOC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM