2011年1月25日 星期二

PHP CURL .htpasswd 認證筆記

<?php
$url = '127.0.0.1/phpmyadmin';
$userid = 'admin';
$userpassword = 'admin';

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERPWD, "$userid:$userpassword");

$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>