From c93803e324f69f50b3971e61037e53952dafefe3 Mon Sep 17 00:00:00 2001 From: Horus3 Date: Wed, 12 Nov 2014 13:02:47 +0100 Subject: Added Request Method + Inlined Redis Cache --- index.php | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index 5980a97..dbc0f01 100644 --- a/index.php +++ b/index.php @@ -102,9 +102,18 @@ a {
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 "

Failure!

Requested URL: \"".htmlentities($_REQUEST['url'])."\"


Couldn't retrieve URL. Please check whether the website is available and try again.
"; } else { @@ -177,6 +201,25 @@ Host: ""
+ +
+ +
+ + + +
+
+
-- cgit v1.2.3