dqm7854 2016-01-26 06:17
浏览 728

通过php从外部连接到本地IP

I have:

  1. Data to connect to external server (IP, login, password).
  2. Ready VPN-tunnel from external server to other machine.
  3. Local IP (192.168.....?wsdl) of this machine with the pack of services to ask (SOAP-query).

Task: Send SOAP-request to Local IP and take an XML-answer.

I know how to realise SOAP-request, but I don't understand how to connect to local IP across VPN, using PHP.

For example, here i send XMLHttpRequest() to 'url' variable. I have direct access to 'url' link. But when the access behind the VPN...

var url = "http://domain.com/MCAExportService/.....asmx";

function getKBM(client_iin) {
...
}

var xmlHTTP = new XMLHttpRequest();
    xmlHTTP.open("POST", url, true);
...
    xmlHTTP.send(xml_request);

UPD: I configured the LAMP on External server. Now I need to write a script, which send SOAP-request to Local server, connected with External server with VPN-tunnel. How can I interview Local server from External with script? And then send a request to it?

  • 写回答

1条回答 默认 最新

  • dongxue163536 2016-01-26 07:49
    关注

    If your server has a simple, single IP address configuration then you would probably be best to hard-code this - it is by far and away the simplest option. If you want to determine it dynamically, here are a few bits of information which you will hopefully find useful:

    $_SERVER['HTTP_HOST'] contains the address that was typed into the address bar of the browser in order to access the page. If you access the page by typing (for example) http://192.168.0.1/index.php into the browser, $_SERVER['HTTP_HOST'] will be 192.168.0.1. If you used a DNS name to access the page, gethostbyname($_SERVER['HTTP_HOST']); will turn that DNS name into an IP address. $_SERVER['SERVER_NAME'] contains the name that has been configured in the web server configuration as it's server name. If you going to use this, you might as well just hard code it in PHP. $_SERVER['SERVER_ADDR'] will contain the operating system of the server's primary IP address. This may or may not be the IP address that was used to access the page, and it may or may not be an IP address with the web server bound to it. It depends heavily on OS and server configuration. if the server has a single IP address, this is probably a safe bet, although there are situations where this may contain 127.0.0.1. The long of the short of it is that there is no 100% reliable way to determine a guaranteed working IP address of the web server, without examining information that was send to the web server in order to generate the page you are creating, which as you say totally defeats its purpose.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?