| Subcribe via RSS

Join the Black Hat Digest Newsletter

Get On The Site Creation Waiting List
Have a new website delivered to you every month! Read more...

How to make your own Twitter Poster in PHP with Curl

December 23rd, 2009 | 1 Comment | Posted in Tutorials

Twitter offers a handy dandy API for posting to itself.  It’s not hard to work with (you just have to organize your data the right way).

You need to have a few variables set up prior to running this.

$message  (what you are posting to twitter — a day or so ago I provided the code to make tinyurls)

$twitter_user =  Your twitter Username
$twitter_password =  Your twitter password

If you have those three variables set you can call the code below and post to twitter with their api url and a wee bit of curl.  Here is the code to do it:

$twitter_api_url = “http://twitter.com/statuses/update.xml?status=”.urlencode(stripslashes(urldecode($message)));
$twitter_data = $message;
$ch = curl_init($twitter_api_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, “{$twitter_user}:{$twitter_password}”);
$twitter_data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//Let’s print out where we posted and what!

echo ‘Posting Message: ‘.$message.’<br> to <br> http://www.twitter.com/’.$twitname.”;
// Let’s print out an error message if things didn’t go well.
if ($httpcode != 200) {
echo “<strong>Don’t Panic!</strong> Something went wrong, and the tweet wasn’t posted.  You Failed.”;
}

That’s really it.  It will post your message to twitter.  You can store your variables in an array, or a database, or a text file.  Along with all your messages and have it go do it’s thing.

Cash in on your Competitors’ Work – SpyFu Ad History

Popularity: 4% [?]

Tags:

Convert Url to Tiny Url

December 22nd, 2009 | No Comments | Posted in Tutorials

Sometimes you need to convert a url to a new one on the fly.  Tinyurl offers a very easy to use API to do that.  You can do it complicated with curl or you can just use file_get_contents and make it a one line function.

function ShortURL($ToConvert) {
$short_url= file_get_contents(“http://tinyurl.com/api-create.php?url=” . $ToConvert);
return $short_url;

}

Just call it with:

$newurl = ShortURL(‘http://www.linktoshorten.com/itsreallylong’);

Cash in on your Competitors’ Work – SpyFu Ad History

Popularity: 1% [?]

Random RSS Item with PHP and ICONV for formatting.

December 19th, 2009 | 4 Comments | Posted in Tutorials

So I had to hack together a little snippet today that would return just one single item from a rss feed and have it be random from the available items.

(For example this snippet of code will return one random rss item from blackhatdigest – skipping the most recent entry)

function load_xml_feed($location)
{
global $value1;
$feedXml = simplexml_load_file($location);

$i= ‘1′;
foreach ($feedXml->channel->item as $article)
{
$title[$i] = (string)$article->title;
$link[$i] = (string)$article->link;
$description[$i] = (string)$article->description;

$i++;

}
$randnumber = rand(2, $i);
$link = trim($link[$randnumber]);
$title = trim($title[$randnumber]);
$description = trim($description[$randnumber]);
$title = iconv(“UTF-8″, “ISO-8859-1″, $title);
$description = iconv(“UTF-8″, “ISO-8859-1″, $description);
$value1 = array($title,$link,$description);
return $value1;
}

$rss = ‘http://feeds.feedburner.com/BlackHatSeoDigest’;
load_xml_feed($rss);
$link = $value1[1];
$title = $value1[0];
$description = $value1[2];

echo $link;
echo $title;
echo $description;

Cash in on your Competitors’ Work – SpyFu Ad History

Popularity: 2% [?]

Tags: , ,