Skip to content

Instantly share code, notes, and snippets.

@daangemist
Created February 1, 2013 09:47
Show Gist options
  • Save daangemist/4690404 to your computer and use it in GitHub Desktop.
Save daangemist/4690404 to your computer and use it in GitHub Desktop.
Small PHP script to request a page with a different Host: header.
<?php
if( isset($_REQUEST['url']) ) {
$url = $_REQUEST['url'];
$host = $_REQUEST['host'];
/* Borrowed from http://stackoverflow.com/questions/9932636/how-to-set-hostname-using-php-curl-for-a-specific-ip */
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: ' . $host));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
die;
}
?>
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#customHost').submit( function(e) {
var url,host;
e.preventDefault();
url = $('input[name=url]').val();
host = $('input[name=host]').val();
$('#targetFrame').attr('src','?url=' + url + '&host=' + host);
});
});
</script>
</head>
<body>
<h1>Request custom page</h1>
<div style="width:20%;float:left;">
<form name="dummy" id="customHost">
<input type="text" name="url" size="30" placeholder="Request (IP or DNS)" /><br />
<input type="text" name="host" size="30" placeholder="Custom host" /><br />
<input type="submit" />
</form>
</div>
<div style="width:80%;float:left;">
<iframe id="targetFrame"></iframe>
</div>
</body>
</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment