summaryrefslogtreecommitdiff
path: root/header/index.php
diff options
context:
space:
mode:
authorHorus32014-11-16 21:20:41 +0100
committerHorus32014-11-16 21:20:41 +0100
commit4168f7aff52f6e7cf7320e42252227dac5169c4a (patch)
treef73e5e93e8bc8d9b5ad8ef415b59ede323663f76 /header/index.php
downloadtools.iamfabulous.de-4168f7aff52f6e7cf7320e42252227dac5169c4a.tar.gz
Initial commit.
Diffstat (limited to 'header/index.php')
-rw-r--r--header/index.php200
1 files changed, 200 insertions, 0 deletions
diff --git a/header/index.php b/header/index.php
new file mode 100644
index 0000000..1a027ab
--- /dev/null
+++ b/header/index.php
@@ -0,0 +1,200 @@
+<?php
+
+if ( isset($_REQUEST['url']) && $_REQUEST['url'] != "" )
+ $set = true;
+else
+ $set = false;
+?>
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
+ <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
+ <style>
+ <?php echo file_get_contents("../tools/style.css"); ?>
+ </style>
+ <noscript><style>.navbar{margin-bottom:0;}</style></noscript>
+ <?php if ( ! $set) { ?>
+ <title>Check HTTP Headers online!</title>
+ <?php } else {
+ echo '<title>Header: ' . htmlentities($_REQUEST['url']) .'</title>';
+ }
+ ?>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel='shortcut icon' href='../tools/favicon.ico' type='image/x-icon'>
+</head>
+<body>
+ <?php require("../tools/navbar.php"); ?>
+<div class="container">
+ <div class="text-center">
+ <div class="row">
+<?php
+if ( $set ){
+ function getInfo($url, $method = "get", $customHeader = array()){
+
+ $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);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_HEADER, 1);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ 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);
+ }
+
+ $response = curl_exec($ch);
+ if ( ! $response )
+ return false;
+ $request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
+ $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
+ $header = substr($response, 0, $header_size);
+ $host = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
+
+ $result = array($request, $header, $host);
+
+ # redis. remove this line if no redis
+ $redis->set( $key, serialize($result), 60 );
+
+ return $result;
+ }
+ 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 {
+ ?>
+ <h1>Success!</h1>
+ <br>
+ <h4><pre>Requested URL: "<u><?php echo strtolower(htmlentities($_REQUEST['url'])); ?></u>"
+Host: "<u><?php echo strtolower(htmlentities($header_info[2])); ?></u>"</pre></h4>
+ <br>
+
+ <h3>Request Header:</h3>
+ <?php
+ echo "<pre>".htmlentities($header_info[0])."</pre>";
+ ?>
+ <h3>Response Header:</h3>
+ <?php
+ echo "<pre>";
+ echo htmlentities($header_info[1]);
+ echo "</pre>";
+ }
+ ?>
+ <p>Entries are cached for 60 seconds.</p>
+<?php
+} else {
+?>
+ <h3>Retrieve HTTP Headers Online!</h3>
+ <p>Check the response headers for websites. <br> Enter a URL and hit the submit button.</p>
+ <br>
+<form class="form-horizontal">
+<fieldset>
+
+<legend></legend>
+<!-- Form Name -->
+
+
+<!-- Text input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="textinput">http://</label>
+ <div class="col-md-5">
+ <input id="url" name="url" placeholder="Insert URL here." class="form-control input-md" required="" type="text">
+ </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-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="header[]">(optional)</label>
+ <div class="col-md-4">
+ <div class="input-group">
+ <input name="header[]" placeholder="Custom request header here." class="form-control input-md" type="text">
+
+<span class="input-group-btn">
+ <button type="button" class="btn btn-default addButton" title="Add more header." onclick="addInput('moreInput')"><i class="fa fa-plus"></i></button>
+</span>
+</div>
+ <span class="help-block text-left">Add any header, which are sent to the server.</span>
+ </div>
+</div>
+
+<span id="moreInput"></span>
+
+<!-- Button -->
+<div class="form-group">
+ <label class="col-md-4 control-label" for=""></label>
+ <div class="col-md-4">
+ <button id="" name="" class="btn btn-primary">Submit</button>
+ </div>
+</div>
+
+</fieldset>
+</form>
+
+<?php
+}
+?>
+ </div>
+ </div>
+</div>
+ <?php require("../tools/footer.php"); ?>
+<script>
+
+//window.onload = function(){
+//};
+function addInput(divName){
+ var newdiv = document.createElement('div');
+ newdiv.className = newdiv.className + "form-group"
+ newdiv.innerHTML = "<label class='col-md-4 control-label' for='header[]'></label><div class='col-md-4'> <input type='text' name='header[]' placeholder='More header.' class='form-control input-md' ></input></div>";
+ document.getElementById(divName).appendChild(newdiv);
+}
+</script>
+</body>