简体   繁体   中英

Load balancer with PHP include, can I include the file from only server A

If I'm using a load balancer with 2 droplets on Digital Ocean.

I want to use a PHP include for an HTML file.

is there anyway to only include the file from server A, not server B?

The use case is that these html files are generated by my customer, and will be written to a single server.

You can write an if statement:

if ($_SERVER['SERVER_NAME'] == "servera.yourdomain.com") {
    include("file.html");
} else {
    include("http://servera.yourdomain.com/path/to/file.html");
}

Note that this will only work for static files like HTML. If you try to include a PHP file through the webserver, it will be executed on the remote server instead of returning the source code.

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