php[tek] 2018 : Call for Speakers

Voting

Please answer this simple SPAM challenge: min(nine, five)?
(Example: nine)

The Note You're Voting On

ZyX
11 years ago
Simple PHP Script to login on a Basic Authentication page.

<?php

/* Access Configuration */
define ('x401_host', 'www.example.com');
define ('x401_port', 80);
define ('x401_user', 'your_username');
define ('x401_pass', 'your_password');

/* Function */
function get401Page($file) {
  
$out  = "GET $file HTTP/1.1\r\n";
  
$out .= "Host: ".x401_host."t\r\n";
  
$out .= "Connection: Close\r\n";
  
$out .= "Authorization: Basic ".base64_encode(x401_user.":".x401_pass)."\r\n";
  
$out .= "\r\n";

   if (!
$conex = @fsockopen(x401_host, x401_port, $errno, $errstr, 10))
       return
0;
  
fwrite($conex, $out);
  
$data = '';
   while (!
feof($conex)) {
      
$data .= fgets($conex, 512);
   }
  
fclose($conex);
   return
$data;
}

/* Code */
if ($source = get401Page('/absolute/path/file.php?get=value')) {
  echo
$source;
} else {
  echo
"I can't connect!";
}

?>

<< Back to user notes page

To Top