X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Frequest%2Fclass_HttpRequest.php;h=b12855ff3161f99fae477feab33a723eac6bc89a;hb=e78ec6458b81a3c665b08f862b8bc16c7a80a41f;hp=e3bb312f9ea3757b0cb0d4dbd7b70a187a567c30;hpb=b44e5e7347f9a1dbd49b5b47d506a4f6526caf2f;p=shipsimu.git diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php index e3bb312..b12855f 100644 --- a/inc/classes/main/request/class_HttpRequest.php +++ b/inc/classes/main/request/class_HttpRequest.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -86,14 +86,13 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { * Checks wether a request element is set * @param $element Name of the request element we want to check * @return $isSet Wether the request element is set - * @throws MissingArrayElementsException Thrown if a request element is not set */ public function isRequestElementSet ($element) { // Is this element found? if (!isset($this->requestData[$element])) { - // Then throw an exception - throw new MissingArrayElementsException(array($this, 'requestData', $element), self::EXCEPTION_MISSING_ELEMENT); - } + // Then return false + return false; + } // END - if // All clear return true; @@ -110,13 +109,14 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { // Initialize value $value = null; - try { - if ($this->isRequestElementSet($element)) { - $value = $this->requestData[$element]; - } - } catch (MissingArrayElementsException $e) { - // Do nothing here - } + // Is the element set? + if ($this->isRequestElementSet($element)) { + // Get the bare value + $value = $this->requestData[$element]; + + // Secure it against attacks + $value = htmlentities(strip_tags($value), ENT_QUOTES); + } // END - if // Return the element's value return $value; @@ -158,7 +158,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { // Does this header exist? if (isset($_SERVER[$name])) { $headerValue = $_SERVER[$name]; - } + } // END - if // Return the value return $headerValue; @@ -176,7 +176,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { /** * Sets wether the request was valid (default: true) * - * @param $isValid Wether the request is valid + * @param $isValid Wether the request is valid * @return void */ public final function requestIsValid ($isValid = true) { @@ -191,6 +191,26 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { public final function isRequestValid () { return $this->requestIsValid; } + + /** + * Reads a cookie and returns it's value or null if not found + * + * @param $cookieName Name of cookie we shall read + * @return $cookieValue Value of cookie or null if not found + */ + public final function readCookie ($cookieName) { + // Default is no cookie with that name found + $cookieValue = null; + + // Is the cookie set? + if (isset($_COOKIE[$cookieName])) { + // Then get it + $cookieValue = $_COOKIE[$cookieName]; + } // END - if + + // Return the value + return $cookieValue; + } } // [EOF]