4

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.

4
  • 2
    Are both sites hosted on the same server? Commented Aug 30, 2011 at 18:10
  • 1
    Is it at all possible to run them on the same server with different virtual hosts? Commented Aug 30, 2011 at 18:11
  • @Michael They are on the same server, but with aliased hosts. site1.com -> ourserver.com/site1 site2.com -> ourserver.com/site2 Commented Aug 30, 2011 at 18:15
  • @Chris Turn your comment into an answer so I can mark it. This solved my problem. Commented Aug 30, 2011 at 18:22

2 Answers 2

2

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);

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

I really like the cURL approach to this. I am thinking of ways this would be more useful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.