0

so what I have is a simple script, set up on two different hosting accounts on the same server,

So Account #1 has a file index.php

<?
function get() {
    return file_get_contents("http://cmyip.com");
}

?>

Account #2 has another file

<?
require_once('../../seaview/public_html/index.php');
echo get();
?>

now what it would do, is execute it on account #1 and then bring back results, how do I import the function(it will be a class later on) and execute it on account #2, only reason I don't want to just copy paste the files into the second account is because there is going to be a lot of accounts, and managing them would be a pain, also note that the accounts do have different IPs, thats how I know that it's executing on account #1

Please help!

Saulius Antanavicius
  • 1,371
  • 6
  • 25
  • 55
  • I removed my answer because I misunderstood your question. What you show is indeed perfectly fine to do (no slowdown, no security problems). What about the above doesn't work at the moment, can you clarify? – Pekka Aug 12 '11 at 07:50
  • Incidentally though, a [question](http://stackoverflow.com/questions/7037051/php-require-once-connect-to-other-website) popped up just this minute where my answer is perfect. SO is really amazing! – Pekka Aug 12 '11 at 07:51
  • It started working now, however the problem now is that outbound connections are made via shared IP, and I need to assign the dedicated IP to all outbound connections, somehow, not sure how yet – Saulius Antanavicius Aug 12 '11 at 07:57
  • mmm, interesting problem. Not sure what can be done about that. Curl may be able to switch IPs - otherwise, you may have to use a command-line tool to do the request – Pekka Aug 12 '11 at 08:01
  • Yep, curl is able to do it via CURLOPT_INTERFACE, however I can't use CURL for this, need to use DOM class, which is turning out to be tricky – Saulius Antanavicius Aug 12 '11 at 08:02
  • The only security issue I can see with this implementation is [DNS poisoning](http://en.wikipedia.org/wiki/DNS_cache_poisoning). – Shoan Aug 12 '11 at 08:03
  • The other issue would be what happens to the calling script when http://cmyip.com goes down. – Shoan Aug 12 '11 at 08:04
  • @Shoan cmyip.com was only used as an example, the real issue here was including the function get() and then executing it, cmyip was just used to see which network interface the script is using – Saulius Antanavicius Aug 12 '11 at 08:07
  • Not sure whether this can be done using the standard fopen functions. You could poke around [stream context options](http://www.php.net/manual/en/context.php) to see whether anything exists, but I've never seen any option to that effect – Pekka Aug 12 '11 at 09:02

1 Answers1

0

I am assuming shared hosting here, if so unless they have enabled 'allow_url_fopen' including php or reading files from one server to another may not be possible.

Some good info as ever on the PHP Manual: http://www.php.net/manual/en/features.remote-files.php

Brian
  • 8,418
  • 2
  • 25
  • 32