简体   繁体   中英

PHP Alternatives to Remote File Inclusion

One of our clients has two very similar websites that we are performing lead tracking on. Currently, I have copies of the files that make this work on both sites, with a single file having the variances that make it unique.

My question is: is there a way to allow both sites to share files? Changing allow_url_fopen is not an option.


@Chris Yes, and both sites dump data into the same MySQL db.

If the sites are hosted on the same server, you can simply use an include/require statement to share the file.

Place the file in a location that is readable for both site configurations, then supply the full path to the file.

For instance:

/www <-- web root
  /siteA <-- first site
  /siteB <-- second site
  /libs  <-- location to store files to be shared by both sites

... then use require_once('/www/libs/file_to_share.php);

If the sites are hosted on the same server and the host allows it, you can simply chdir() to the correct (shared) directory at the beginning of one of the sites' scripts.

Alternatively, you can get the file(s) with cURL, dump it/them to a file and then include() it/them.

Including remote files is slower no matter how you do it, and not really recommended for a web page as it will massively increase the server traffic/load and page load time.

EDIT Based on what you say about the way the domains are working, you could also point both sites to the same location examine $_SERVER['HTTP_HOST'] to determine which site-specific file to include.

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