diff options
author | Thomas Lange <code@nerdmind.de> | 2019-08-29 18:45:48 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2019-08-29 18:54:15 +0200 |
commit | 84e2b2be6f7537e0a4a9f0c323555404d2682a8a (patch) | |
tree | 29bc6220e4e545fcf1d5939810de9ba9e7311c8f /PHP/HTTP-Class/index.php | |
parent | 9d0bb6823b77ae68128e83d13f2125d65735b1b3 (diff) | |
download | snippets-84e2b2be6f7537e0a4a9f0c323555404d2682a8a.tar.gz snippets-84e2b2be6f7537e0a4a9f0c323555404d2682a8a.tar.xz snippets-84e2b2be6f7537e0a4a9f0c323555404d2682a8a.zip |
Add HTTP class
This class was written in 2015 and originally had it's own repository. I decided to include it to the snippets repository because this piece of code does not need it's own repository.
Diffstat (limited to 'PHP/HTTP-Class/index.php')
-rwxr-xr-x | PHP/HTTP-Class/index.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/PHP/HTTP-Class/index.php b/PHP/HTTP-Class/index.php new file mode 100755 index 0000000..cc52561 --- /dev/null +++ b/PHP/HTTP-Class/index.php @@ -0,0 +1,71 @@ +<?php +#============================================================================== +# Include HTTP class +#============================================================================== +require_once 'include/HTTP.php'; + +#============================================================================== +# Initialize HTTP class +#============================================================================== +HTTP::init(); + +#============================================================================== +# Check if GET parameters are set +#============================================================================== +if(HTTP::issetGET('parameter_one', 'parameter_two', 'parameter_three')) { + $parameter_one = HTTP::GET('parameter_one'); + $parameter_two = HTTP::GET('parameter_two'); + + var_dump($parameter_one, $parameter_two, HTTP::GET('parameter_three')); +} + +#============================================================================== +# Check if POST parameters are set +#============================================================================== +if(HTTP::issetPOST('parameter_one', 'parameter_two', 'parameter_three')) { + $parameter_one = HTTP::POST('parameter_one'); + $parameter_two = HTTP::POST('parameter_two'); + + var_dump($parameter_one, $parameter_two, HTTP::POST('parameter_three')); +} + +#============================================================================== +# Check if POST parameters in conjunction with a specific value are set +#============================================================================== +if(HTTP::issetPOST('parameter_one', 'parameter_two', ['parameter_three' => 'value_three'])) { + // do something +} + +#============================================================================== +# Check the HTTP request method +#============================================================================== +if(HTTP::requestMethod('GET') OR HTTP::requestMethod('POST') OR HTTP::requestMethod('HEAD')) { + // do something +} + +#============================================================================== +# Get the HTTP request method +#============================================================================== +$requestMethod = HTTP::requestMethod(); + +#============================================================================== +# Get the HTTP status code of the current request +#============================================================================== +$statusCode = HTTP::responseStatus(); + +#============================================================================== +# Send a HTTP status code to the client +#============================================================================== +HTTP::responseStatus(200); + +#============================================================================== +# Send a custom HTTP response header to the client +#============================================================================== +HTTP::responseHeader(HTTP::HEADER_CONTENT_TYPE, HTTP::CONTENT_TYPE_TEXT); + +#============================================================================== +# Send a HTTP redirect to the client and stop script execution +#============================================================================== +# HTTP::redirect('https://example.org/'); +# HTTP::redirect('https://example.org/', 303); +?>
\ No newline at end of file |