开发者

How to get the domain/Server IP on which html page is running?

I have a HTML page on server. When the page runs on a local sys开发者_JAVA技巧tem from server, can I somehow get the server IP from which the page is running?

Actually I have two HTML pages A (coded in HTML) & B (coded in flex) saved on server at same location. Through page A I am redirecting to page B. So for redirection I need to specify the url on which page B is located. I dont want to hardcode this URL because I have run these two pages on several servers, and each time I run on diff server I have to change the url.

So is there any possible by which I can find out on which server page A is running so that dynamically I can form the url for page B?


How do you implement the redirect?

The simplest solution would not require you to find that information at all: simply use a relative redirect.

If A is located at http://myserver.com/dir/a.html and B is located at http://myserver.com/dir/b.html, then simply redirect to b.html in A and you should be fine.


You could use flex to get your local server's IP..

In Flex you use 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 
} 

Also please check out [Get a Client IP Address with a RemoteObject Call] http://cookbooks.adobe.com/index.cfm?event=showdetails&postId=3462

Alternatively, if you have SSI enabled on the server, you can use that to get your documents URI:

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

Or even better the Document Root / SERVER_ADDR

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

For more options, check: http://www.ssi-developer.net/ssi/ssi-echo.shtml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜