Skip to content

httpSetResponseCode

Server-side
Caution

This function works only in the HTTP interface, meaning in .html files - it is not available in .lua files.

This function sets the HTTP status code that will be sent for the current HTML page.

Syntax

bool httpSetResponseCode ( ​int code )
Required arguments

Returns

Returns true if the code was set successfully, false otherwise.

  • bool: result

Code Examples

server

In this example, when accessing the resource web page, if the logged-in user is not in the IT_Admin ACL group, a Page not found message is displayed and a 404 status code is returned. If the user is in the specified group, the page displays the text Hello admin.

<html>
<*
if (not isObjectInACLGroup("user."..getAccountName(user), aclGetGroup('IT_Admin'))) then
httpSetResponseCode(404)
*>
<h1>Page not found!</h1>
<*
else
*>
<head>
<title>Hello</title>
</head>
<body>
Hello admin!
</body>
<*
end
*>
</html>