开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜