Skip to content

Instantly share code, notes, and snippets.

@kurorido
Created April 16, 2016 14:55
Show Gist options
  • Save kurorido/94a7b934eae46bb79305faffe07dc372 to your computer and use it in GitHub Desktop.
Save kurorido/94a7b934eae46bb79305faffe07dc372 to your computer and use it in GitHub Desktop.
Fake Proxy Login
<?php
set_error_handler(function($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
});
$username = $_POST['username'];
$password = $_POST['password'];
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
));
try {
$url = 'http://www.msn.com.tw/';
$data = file_get_contents($url, false, $context);
} catch(Exception $e) {
$pos = strpos($e->getMessage(), '401 Unauthorized');
if($pos !== false) {
echo "failed";
} else {
echo "success";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment