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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧