23 Jun 2008

Twitter Php Script Without Curl

This is a simple PHP script to interact with the Twitter API and update the user’s status. Unlike most other samples, it does not use cURL or any other dependency.

$msg = 'Your message here';

$out = "POST http://twitter.com/statuses/update.json HTTP/1.1\r\n"
  ."Host: twitter.com\r\n"
  ."Authorization: Basic ".base64_encode ('username:password')."\r\n"
  ."Content-type: application/x-www-form-urlencoded\r\n"
  ."Content-length: ".strlen ("status=$msg")."\r\n"
  ."Connection: Close\r\n\r\n"

$fp = fsockopen ('twitter.com', 80);
fwrite ($fp, $out);
fclose ($fp);

Note that this script does not store or process the response.