4D v13.4

On Web Connection Database Method

Home

 
4D v13.4
On Web Connection Database Method

On Web Connection Database Method  


 

 

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.

Compatibility note: The database method is also called when a context is created in contextual mode (obsolete mode that could be used in converted 4D databases).

The request should have been previously 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 that are passed by 4D. The contents of these parameters are as follows:

ParametersTypeDescription
$1TextURL
$2TextHTTP header + HTTP body (up to 32 kb limit)
$3TextIP address of the Web client (browser)
$4TextIP address of the server
$5TextUser name
$6TextPassword

You must declare these parameters as follows:

  ` On Web Connection Database Method
 
 C_TEXT($1;$2;$3;$4;$5;$6)
 
  ` Code for the method
  • URL extra data

    The first parameter ($1) is the URL entered by the user in the location area of his or her Web browser, from which the host address has been removed.
    Let’s take the example of an Intranet connection. Suppose that the IP address of your 4D Web Server machine is 123.4.567.89. The following table shows the values of $1 depending on the URL entered in the Web browser:

    URL entered in Web browser Location areaValue of parameter $1
    123.4.567.89/
    http://123.4.567.89/
    123.4.567.89/Customers/Customers
    http://123.4.567.89/Customers/Customers
    http://123.4.567.89/Customers/Add/Customers/Add
    123.4.567.89/Do_This/If_OK/Do_That/Do_This/If_OK/Do_That

    Note that you are free to use this parameter at your convenience. 4D simply ignores the value passed beyond the host part of the URL.
    For example, you can establish a convention where the value "/Customers/Add" means “go directly to add a new record in the [Customers] table.” By supplying the Web users of your database with a list of possible values and/or default bookmarks, you can provide shortcuts to the different parts of your application. This way, Web users can quickly access resources of your Web site without going through the whole navigation path each time they make a new connection to your database.

WARNING: In order to prevent a user from reentering a database with a bookmark created during a previous session, 4D intercepts any URL that corresponds to one of the standard 4D URLs.

  • Header of the HTTP request followed by the HTTP body
    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 it is. Its contents will vary depending on the nature of the Web browser which is 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 deals with this information, it is up to you to parse the header and the body.
    Note: For performance reasons, the size of these 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.
  • IP address of the server
    The $4 parameter receives the IP address to which the HTTP request was sent. 4D allows for multi-homing, which allows you to exploit 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. 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...) 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.

 
PROPERTIES 

Product: 4D
Theme: Web Server

 
SEE ALSO 

Database Methods
On Web Authentication Database Method
URLs and Form Actions