Reputation: 1131
My website runs on a public web server A which does not see my local server B located on my intranet. In my browser, if I am in my office, I can access my intranet in the address field of my browser. I can also display an image located in my local server B on a page built from my web server A. However if I use file_exists(file on server B) in php running on server A, it does not work as the php script is running on server A which does not see server B.
I need to detect if the browser can access server B (is in the office or tunnelling via vpn) so I can decide if I display/download the local files on server B or the files on the web server A. How can I do that?
I also need that function to see if I can call my asterisk server to place a call on my pabx.
Upvotes: 0
Views: 1253
Reputation: 394
When you access the server A, the script can evaluate your address (your office address) and know that it is in a set of addresses that can show images from server B. If you access server A from outside the office, the script can then be set to not display images from B.
You find the appropriate variable in
while(list($key, $val) = each($_SERVER))
{
$$key = $val;
printf("%s = %s \n",$key, $val);
}
Of course the proposed solution to look at HTTP headers above and evaluate if
[0] => HTTP/1.1 200 OK
is present or not when trying to reach server B would do the trick as well, but you need to do a failed access to a server you might already know from the IP will fail.
Admitting, this is a "hardcode" scenario as you need to understand what IP is OK at server A - and that may change. Possibly a javascript solution in the client would be more smooth in this case.
Upvotes: 0
Reputation: 4461
If I understand you correct, this http://php.net/manual/en/function.get-headers.php might be helpful. You can "ping" any file on remote server, check returned headers and if returned code is 200 - server is accessble.
Upvotes: 1