diff options
| author | Horus3 | 2014-11-12 13:02:47 +0100 |
|---|---|---|
| committer | Horus3 | 2014-11-12 13:02:47 +0100 |
| commit | c93803e324f69f50b3971e61037e53952dafefe3 (patch) | |
| tree | 62a31249ab65cb227a74459b2207058ec6c7057c | |
| parent | bdb371491a0b79029f180d54d76910efa8f5c79e (diff) | |
| download | httpheader-c93803e324f69f50b3971e61037e53952dafefe3.tar.gz | |
Added Request Method + Inlined Redis Cache
| -rw-r--r-- | index.php | 49 | ||||
| -rw-r--r-- | redis.php | 18 |
2 files changed, 46 insertions, 21 deletions
@@ -102,9 +102,18 @@ a { <div class="row"> <?php if ( $set ){ - function getInfo($url, $customHeader = array()){ + function getInfo($url, $method = "get", $customHeader = array()){ - require 'redis.php'; + $redis = new Redis(); + $redis ->connect("/var/run/redis/redis.sock"); + $redis->ping(); + $redis->select(9); + + $key = md5( $url . serialize($customHeader) ); + + if( $redis->exists( $key ) ){ + return unserialize( $redis->get( $key ) ); + } $agent = "Retrieve HTTP headers online. v0.1"; $ch = curl_init($url); @@ -114,6 +123,16 @@ if ( $set ){ curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLINFO_HEADER_OUT, 1); + switch($method){ + case("head"): + curl_setopt($ch, CURLOPT_NOBODY, true); + break; + case("post"): + curl_setopt($ch, CURLOPT_POST, true); + default: + break; + } + if ( ! empty($customHeader) ){ curl_setopt($ch, CURLOPT_HTTPHEADER, $customHeader); } @@ -133,7 +152,12 @@ if ( $set ){ return $result; } - $header_info = getInfo($_REQUEST['url'], $_REQUEST['header']); + if ( ! isset($_REQUEST['method']) || $_REQUEST['method'] != "" ){ + $_REQUEST['method'] = 'get'; + } else { + $_REQUEST['method'] = strtolower($_REQUEST['method']); + } + $header_info = getInfo($_REQUEST['url'], $_REQUEST['method'], $_REQUEST['header']); if ( ! $header_info ){ echo "<h1>Failure!</h1><h3>Requested URL: \"".htmlentities($_REQUEST['url'])."\"</h3><hr></pre><pre>Couldn't retrieve URL. Please check whether the website is available and try again.</pre>"; } else { @@ -177,6 +201,25 @@ Host: "<u><?php echo strtolower(htmlentities($header_info[2])); ?></u>"</pre></h </div> </div> +<!-- Multiple Radios (inline) --> +<div class="form-group"> + <label class="col-md-4 control-label" for="method">Method</label> + <div class="col-md-4"> + <label class="radio-inline" for="method-0"> + <input name="method" id="method-0" value="GET" checked="checked" type="radio"> + GET + </label> + <label class="radio-inline" for="method-1"> + <input name="method" id="method-1" value="POST" type="radio"> + POST + </label> + <label class="radio-inline" for="method-2"> + <input name="method" id="method-2" value="HEAD" type="radio"> + HEAD + </label> + </div> +</div> + <br> <!-- Text input--> diff --git a/redis.php b/redis.php deleted file mode 100644 index 36e0d98..0000000 --- a/redis.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -$redis = new Redis(); -$redis ->connect("/var/run/redis/redis.sock"); -$redis->ping(); -$redis->select(9); - -$key = md5( $url . serialize($customHeader) ); - -if( $redis->exists( $key ) ){ - return unserialize( $redis->get( $key ) ); -} - -/* -if ( $setCache ){ - $redis->set( $key, serialize($result), 60 ); -} -*/ |
