Skip to content

Instantly share code, notes, and snippets.

@janpieper
Created November 17, 2011 22:50
Show Gist options
  • Save janpieper/1374819 to your computer and use it in GitHub Desktop.
Save janpieper/1374819 to your computer and use it in GitHub Desktop.
Small script to check if the Referer-bug is still existent at fliplife.com
<?php
/**
* Send HTTP request to "fliplife.com" and return the HTTP status.
*
* @param array $headers Associative array with HTTP request headers.
* @throws Exception If no HTTP status can be found.
* @return integer HTTP status.
*/
function requestFliplife(array $headers)
{
$socket = fsockopen('fliplife.com', 80);
fwrite($socket, "GET / HTTP/1.1\r\n");
foreach ($headers as $name => $value) {
fwrite($socket, "{$name}: {$value}\r\n");
}
fwrite($socket, "\r\n");
$response = '';
while (($line = fgets($socket)) !== false) {
$response .= $line;
}
fclose($socket);
if (!preg_match('/HTTP\/1.[01] (?<httpStatus>\d+)/', $response, $matches)) {
throw new Exception('Got invalid response. No HTTP status found.');
}
return (int)$matches['httpStatus'];
}
/**
* HTTP request configuration.
*/
$requests = array(
'Request without Referer' => array(
'Host' => 'fliplife.com',
'Connection' => 'close'
),
'Request with empty Referer' => array(
'Host' => 'fliplife.com',
'Connection' => 'close',
'Referer' => ''
),
'Request with Referer' => array(
'Host' => 'fliplife.com',
'Connection' => 'close',
'Referer' => 'http://www.adcloud.com/'
)
);
/**
* Execute all configured requests and validate their HTTP response status.
*/
echo PHP_EOL;
foreach ($requests as $description => $headers) {
echo str_pad($description, 30, ' ', STR_PAD_LEFT) . ': ';
echo requestFliplife($headers) === 200 ? 'Success' : 'Failed';
echo PHP_EOL;
}
if (stripos(PHP_OS, 'WIN') === false) echo PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment