Headers response

Never been easier to build forms then this really well builed framework. Example bellow is how to use it in Control Tower and not outside.

Class meta

  • Name: headers
  • Namespace: request\headers
  • Construct: NULL
  • Dependencies: NULL

Some defualt headers

Usefull some shortcut headers you could use.

$this->modal()->headers()
->contentType("text/html", "UTF-8")
->frameOption("SAMEORIGIN")
->xxsProtection(1)
->contentTypeOptions("nosniff")
->headerAllowOrigin();

$this->modal()->headers()->send("[HTML CODE HERE]");

Example: 404

$this->modal()->headers()->set(404);
$this->modal()->headers()->send("<h1>404 Sidan kunde inte hittas</h1>");

Example: 301 and redirect

$this->modal()->headers()->set(301);
$this->modal()->headers()->location("https://example.se/page1");
$this->modal()->headers()->send();

Example: cache

This example shows how to cache a javascript file. It works just as good with json and xml files.

$this->modal()->headers()->add(["Content-Type" => "application/javascript"]);
$this->modal()->headers()->cache(31536000);
$this->modal()->headers()->send("[JAVASCRIPT CODE HERE]");

Method list

Set status code
@param int $status
@return self
set(int $status)
Read status code
@param The argument is DEPRECATED. Use only to get and not set
@return int
status(?int $status = NULL)
Set header
@param string $key
@param string $value
@return self
setHeader(string $key, $value)
Set multiple headers
@param Array $array
@return self
add(array $array)
Set location (redirect URL)
@param string $url
@return self
location(string $url)
Get/return all codes and messages
@return array
codes()
Get the status message
@return string status message
message()
Execute headers and send content to body
@param string|null $content
@param int|null $status overwrite status
send(string $content = NULL, ?int $status = NULL)
Add Cache headers
@param integer $timelaps How log cache will last
@return ?
cache(int $timelaps = 3600, string $pragma = "cache")
Cache file until it has changed
@param string $fileDir The
cacheFile(string $fileDir)
Disabel/dlear cache headers
@return self
noCache()
Shortcut: Character set
@param string $charset charset
@return self
contentType(string $value = "text/html", string $charset = "UTF-8")
Shortcut: Set json contentType
@param string $charset charset
@return self
json(string $charset = "UTF-8")
Shortcut: Frame options
@param string $key DENY, SAMEORIGIN, ALLOW-FROM https://example.com/ (OK Browser suppert)
@return self
frameOption($key = "DENY")
Shortcut: Add XXS protection
@param int 0|1
@return self
xxsProtection($i = 1)
Shortcut: Add nosniff
@return self
contentTypeOptions($val = "nosniff")
Shortcut: Allow robot index
@return self
robotsTag($follow = "noindex, nofollow")
Shortcut: Access Control, Allow orgin
@param string $value default value ""
@return self
headerAllowOrigin($value = "*")
Check if is Ajax
@return boolean
isAjax()
Get domain extention
@return string
domainExtention()
Check Post Size
@return boolean
checkPostSize()
Check Serves Maximum Post Size
@return number
maxPostSize()