如何获取运行html页面的域/服务器IP?

时间:2011-04-28 06:25:00

标签: html

我在服务器上有一个HTML页面。当页面从服务器在本地系统上运行时,我能以某种方式获取运行该页面的服务器IP吗?

实际上我有两个HTML页面A(用HTML编码)& B(以flex编码)保存在同一位置的服务器上。通过页面A,我将重定向到页面B.因此,对于重定向,我需要指定页面B所在的URL。我不想硬编码这个URL因为我在几台服务器上运行这两个页面,每次我在差异服务器上运行时我都要更改网址。

那么有什么可能的,我可以找到哪个服务器页面A正在运行,以便动态地我可以形成页面B的URL?

2 个答案:

答案 0 :(得分:0)

如何实施重定向?

最简单的解决方案根本不需要您查找信息:只需使用相对重定向。

如果A位于http://myserver.com/dir/a.html且B位于http://myserver.com/dir/b.html,则只需重定向到A中的b.html,您就可以了。

答案 1 :(得分:0)

您可以使用flex获取本地服务器的IP ..

在Flex中,您使用HttpService ....

import mx.managers.CursorManager; 
import mx.rpc.events.FaultEvent; 
import mx.rpc.events.ResultEvent; 
import mx.rpc.http.HTTPService; 

public function readIP() 
{ 
    networkService = new HTTPService(); 
    networkService.useProxy=false; 
    networkService.method="POST"; 
    networkService.url = "http://www.something.com//getip.php"; 
    networkService.addEventListener(ResultEvent.RESULT, readResult); 
    networkService.addEventListener(FaultEvent.FAULT, readFailed); 
    networkService.send();   
    CursorManager.setBusyCursor(); 
} 

private function readResult(event: ResultEvent):void 
{   
    //Process Result 
    CursorManager.removeBusyCursor(); 
} 

private function readFailed(event: FaultEvent):void 
{ 
    //Process Failure 
} 

另请查看[使用RemoteObject调用获取客户端IP地址] http://cookbooks.adobe.com/index.cfm?event=showdetails&postId=3462

或者,如果您在服务器上启用了SSI,则可以使用它来获取文档URI:

The URI of this document is: <!--#echo var="DOCUMENT_URI" -->

甚至更好的文档根/ SERVER_ADDR

The Document root of this document is: <!--#echo var="DOCUMENT_ROOT" -->
The Server Address of this document is: <!--#echo var="SERVER_ADDR" -->

有关更多选项,请检查: http://www.ssi-developer.net/ssi/ssi-echo.shtml