|
Identifying Remote Hosts
| [Previous] [Main] [Next] |
|
| |
| The htmlCgi class makes it easy to identify the IP address of the remote computer accessing your application. To do so, simply instantiate an htmlCgi object, then check the Remote_Addr and Remote_Host member variables.
| |
|
| |
| Remote_Addr is always available, and contains the IP address of the remote client host or proxy server that originated the request.
| |
|
| |
| Remote_Host is usually available, and represents the reverse lookup hostname and domain name (e.g., ppp110.connectup.com) associated with the IP address in Remote_Addr. The value isn't always available because many DNS servers are often not configured to report the information.
| |
|
| |
| You could use this capability to generate custom content based on who views the documents, such as presenting tailored pages to users from certain companies or networks.
| |
|
| |
|
| |
| #include <stdio.h>
| |
| #include <stdlib.h>
| |
| #include <dcmicro/htmlpp/htmlpp.h>
| |
|
| |
| int main( void )
| |
| {
| |
| htmlPage page( "html++ example application" ) ;
| |
|
| |
| // Construct an htmlCgi object to receive
| |
| // the CGI form data from standard input.
| |
| htmlCgi server( cin ) ;
| |
|
| |
| // Output variables that identify the remote host
| |
| page << "Remote_Addr: " << server.Remote_Addr
| |
| << htmlBreak()
| |
| << "Remote_Host: " << server.Remote_Host ;
| |
|
| |
| server << page ;
| |
| return 0 ;
| |
| }
| |
|
| |
|
| |
| Content-Type: text/html
| |
| <HTML>
| |
| <HEAD>
| |
| <TITLE>html++ example application</TITLE>
| |
| </HEAD>
| |
| <BODY>
| |
| Remote_Addr: 206.222.111.14<BR>
| |
| Remote_Host: ip111-14.connectup.com
| |
| </BODY>
| |
| </HTML>
| |
|
| |
