Skip to content

Adding custom headers to requests

Some applications built with ExeOutput for PHP function as custom browsers used to navigate websites. It is possible to add custom headers to the HTTP request headers, allowing you to identify the user by passing some ID of the browser/machine being used, and take appropriate actions.

Note

Headers are name/value pairs that appear in both request and response messages. The name of the header is separated from the value by a single colon.

Insert the following HEScript code in your UserMain script (see how to do this) to create a custom HTTP header. Modify the My Header Name and My Header Value fields.

procedure OnStartMainWindow;
begin
// When the main window is going to be displayed (just before the homepage is shown).
SetUIProp("crm", "CustomHeaderName", """My Header Name""");
SetUIProp("crm", "CustomHeaderValue", """My Header Value""");
end;  

This can be done in the OnStartMainWindow HEScript event.

Warning

In this specific case, the third parameter should use double quotes for string values """String Value""" and single quotes for functions (to be interpreted by the script engine): "MD5OfAString(...)"

Tutorial: How to send a unique computer ID to a remote server

  • Go to the "Scripting" page and double-click on "UserMain".

  • Locate the OnStartMainWindow event and replace it with the following code:

procedure OnStartMainWindow;
begin
 // When the main window is going to be displayed (just before the homepage is shown).
 SetUIProp("crm", "CustomHeaderName", """My-SystemID""");
 SetUIProp("crm", "CustomHeaderValue", "MD5OfAString(""MySystemID"" + GetManualHardwareID(2))");
end;

GetManualHardwareID is an HEScript function that returns a unique system ID based on hardware specifications. The "2" argument indicates that the unique ID will be based on CPU specifications such as CPU ID. We also generate an MD5 hashsum of the system ID.

  • Now when you navigate to any remote URL (http://www.yoursite.com/....), a custom HTTP header called My-SystemID is added to the request. You can read this header with a PHP script placed on your remote server. For instance, the following PHP script prints all request HTTP headers:
<?php
foreach (getallheaders() as $name => $value) {
 echo "$name: $value\n";
}       

The following screenshot shows the result of the code above:

Custom HTTP Headers

As you can see, there is a custom HTTP header named My-SystemID with the appropriate MD5 hashsum.

Scripting with HEScript