My project for Week 3 of the 52 Weeks of Code Challenge - a simple Twitter status update application.
The interface:

The main code:
The function code (API.php):
The interface:

The main code:
<?php $username ='username'; $password ='password'; require('API.php'); if(isset($_POST['msg'])){ $status=$_POST['msg']; if(strlen($status)<1){ $err=1; //Nothing entered in form. } else if (strlen($status)>140) { $err=2; //Too much data entered. } else { $update=twitPost($username, $password, $status); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>52 Weeks of Code :: Week 3 :: Twitter API Applied</title> </head> <body> <h2>Update Twitter</h2> <?php if(isset($err)){ if ($err==1) { echo "<p style='color:red;font-weight:bold;'>j00 din't enters a msg.</p>"; } else if ($err==2) { echo "<p style='color:red;font-weight:bold;'>j00 enters 2 much msg.</p>"; } else { //No message to display. } } ?> <p><strong>What's a-happening, hot stuff?</strong></p> <form action="twil.php" method="post"> <input name="msg" type="text" id="msg" /> <input type="submit" name="button" value="Submit" /> </form> </body> </html>
The function code (API.php):
<?php function twitPost($username,$password,$msg){ $cnx = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($msg))); $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $cnx); curl_setopt($cURL, CURLOPT_VERBOSE, 1); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cURL, CURLOPT_USERPWD, "$username:$password"); curl_setopt($cURL, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($cURL, CURLOPT_POST, 1); $result = curl_exec($cURL); $array = curl_getinfo($cURL); curl_close($cURL); if($array['http_code'] == "200"){ $twitter='Ur msg rawks.'; } else { $twitter="Ur msg iz teh suxx0rz."; } return $twitter; } ?>
0 Comments On This Entry
← January 2021 →
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
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 |
Tags
My Blog Links
Recent Entries
Recent Comments
Search My Blog
0 user(s) viewing
0 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)