harayoki
2007年05月16日 12:59
Although the HTTP_AUTHORIZATION parameter is not available, you may still login to websites requiring basic authentication by formatting your url appropriately:
string username = "Your Name";
string password = "Your Password";
string url = "http://" + llEscapeURL(username) + ":" + llEscapeURL(password) + "@domain.com/page.php";
<?php
function postToTwitter($username,$password,$message){
$host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message)));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
$resultArray = curl_getinfo($ch);
curl_close($ch);
if($resultArray['http_code'] == "200"){
echoStatus(TRUE,"");
} else {
echoStatus(FALSE,"http_code is ".$resultArray['http_code']);
}
}
function echoStatus($bOn,$errormes){
if($bOn){
echo "success";
}else{
echo "error ".$errormes;
}
}
$p_user = $_POST['user'];
$p_password = $_POST['password'];
$p_message = $_POST['message'];
if($p_user==""){
echoStatus(FALSE,"invalid username");
}else if($p_password==""){
echoStatus(FALSE,"invalid password");
}else if($p_message==""){
echoStatus(FALSE,"invalid message");
}else{
postToTwitter($p_user,$p_password,$p_message);
}
?>