The On Web Connection Database Method can be called in the following cases:
- the web server receives a request beginning with the 4DCGI URL.
- the web server receives an invalid request.
For more information, refer to the paragraph “On Web Connection Database Method Calls” below.
The request should have previously been accepted by the On Web Authentication database method (if it exists) and the web server must be launched.
The On Web Connection Database Method receives six text parameters passed by 4D ($1, $2, $3, $4, $5, and $6). These parameters are described in the following table:
Parameters | Type | Description |
$1 | Text | URL |
$2 | Text | HTTP header + HTTP body (up to 32 kb limit) |
$3 | Text | IP address of the Web client (browser) |
$4 | Text | IP address of the server |
$5 | Text | User name |
$6 | Text | Password |
You must declare these parameters as shown below:
C_TEXT($1;$2;$3;$4;$5;$6)
- Header and body of the HTTP request
The second parameter ($2) is the header and the body of the HTTP request sent by the web browser. Note that this information is passed to your On Web Connection Database Method "as is". Its contents will vary depending on the nature of the web browser attempting the connection.
With Safari running on Mac OS, you may receive a header similar to this:
GET /favicon.ico HTTP/1.1
Referer: http://123.45.67.89/4dcgi/test
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; fr-fr) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10
Cache-Control: max-age=0
Accept: */*
Accept-Language: fr-fr
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: 123.45.67.89
With Microsoft Internet Explorer 8 running on Windows, you may receive a header similar to this:
GET / HTTP/1.1
Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
Accept-Language: fr-FR
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)
Accept-Encoding: gzip, deflate
Host: 123.45.67.89
Connection: Keep-Alive
If your application uses this information, it is up to you to parse the header and the body.
Note: For performance reasons, the size of this data cannot be more than 32 KB. Beyond this, they are truncated by the 4D HTTP server.
- IP address of the web client
The $3 parameter receives the IP address of the browser’s machine. This information can allow you to distinguish between intranet and internet connections.
Note: 4D returns IPv4 addresses in a hybrid IPv6/IPv4 format written with a 96-bit prefix, for example ::ffff:192.168.2.34 for the IPv4 address 192.168.2.34. For more information, refer to the Support of IPv6 section.
- IP address of the server
The $4 parameter receives the IP address requested by the 4D Web Server. 4D allows for multi-homing, which allows you to use machines with more than one IP address. For more information, please refer to the section Web Server Settings.
- User Name and Password
The $5 and $6 parameters receive the user name and password entered by the user in the standard identification dialog box displayed by the browser, if applicable. This dialog box appears for each connection, if the Use Passwords option has been selected in the Database Settings dialog box (see section Connection Security).
Note: If the user name sent by the browser exists in 4D, the $6 parameter (the user’s password) is not returned for security reasons.
The On Web Connection Database Method can be used as the entry point for the 4D Web server, either using the special 4DCGI URL, or using customized command URLs.
Warning: Calling a 4D command that displays an interface element (DIALOG, ALERT, etc.) ends the method processing.
The On Web Connection Database Method is therefore called in the following cases:
- When 4D receives the /4DCGI URL. The database method is called with the /4DCGI/<action> URL in $1.
- When a Web page is called with a URL of type <path>/<file> is not found. The database method is called with the URL (*).
- When a Web page is called with a URL of type <file>/ and no home page has been defined by default. The database method is called with the URL (*).
(*) In this particular cases, the URL received in $1 does NOT start with the "/" character.