1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| <?php
$username ='fffffff';
$password ='ffffffff';
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);
// Look at the returned header
$resultArray = curl_getinfo($ch);
curl_close($ch);
if($resultArray['http_code'] == "200"){
$twitter_status='Your message has been sent, <a href="http://twitter.com/'.$username.'">Look!</a>';
} else {
$twitter_status="Error posting to Twitter. Retry";
}
return $twitter_status;
}
?>
<?php
if(isset($_POST['message'])){
$message=$_POST['message'];
if(strlen($message)<1){
$error=1;
} else {
$twitter_status=postToTwitter($username, $password, $message);
}
}
?>
<html>
<head>
<style type="text/css">
#container {
margin: 0 auto;
width: 560px;
}
h1 {
font-size: 2em;
font-family: 'Lucida Grande',sans-serif;
padding-left: 20px;
}
input[type="text"] {
height: 30px;
width: 520px;
padding: 5px;
font-family: 'Lucida Grande',sans-serif;
font-size: 1.15em;
line-height: 1.1;
}
input[type="submit"] {
height: 30px;
margin-right: 15px;
padding: 5px;
font-family: 'Lucida Grande',sans-serif;
font-size: .8em;
}
.error {
background: #FFFFCC;
margin-bottom: 10px;
padding: 4px;
text-align: center;
}
</style>
</head>
<body>
<div id="container">
<h1>Send a Message to Twitter</h1>
<form action="twitter.php" method="post">
<p style="text-align:center;">
<input type="text" name="message" id="message" maxlength="140" />
</p>
<p style="text-align:right;">
<input type="submit" name="button" id="button" value="Tweet!" />
</p>
</form>
<?php if(isset($_POST['message']) && !isset($error)){?>
<div class="error"><?php echo $twitter_status ?></div>
<?php } else if(isset($error)){?>
<div class="error">Error: please insert a message!</div>
<?php }?>
</div>
</body>
</html> |
Partager