Check Out

Blog Stats

about.me

I spend most of my time with WordPress, PHP and Javascript and specialize in LAMP/LEMP stack development. I love to designe web application architecture and to play with cutting edge tools. I love Symfony, Silex, jQuery, Backbone, Underscore and Laravel.

Month: May 2009

hmm, tough question for me. i have (had actually) so many favorites depending on context. but definitely it’s interesting to write here about them

1. notepad – i am a notepad fan, for a very long time since 98 to 2006 and still i like it very much. but well, after that i’d found notepad++ and i liked it for it’s outstanding syntax highlighting features. if by any chance, i have to use windows these days, i work in notepad++

2. visual studio 6: yup, i must agree it is one of the best ide i’ve ever came in touch with. i have worked on visual basic for a long time (99 to 2006) and i was simply in love with visual studio ide. and it’s awesome intellisense + gui designer was the center of the attraction.

3. zend studio: i still use it. its one of my most favorite ide because of it’s os independent distribution. i like most of the features in it (SQL editor, subversion support, FTP etc) and ofcourse the feature to check the output of yourcode inside it. the object inspector is really a very cool feature. and i also use “find in files” feature very often to find the file i am particularly looking to edit. oh by the way – i use the old version (the non-eclipse version) and still use the 5.5.1 version for my everyday development.

4. phped: its a good editor for windows (never tried it’s linux version) but for some unknown reason i’ve failed to get used to with it.

5. netbeans: its superb :) i like it very much. but as i am used to with zend studio i dont use it much. but i always suggest netbeans to someone who is looking for a decent and powerful ide for php (well, yeah also for java specially for the outstanding GUI designer for swing based apps)

6. aptana studio and spket ide : both of them are very very good for editing javascript. i use spket in linux for it’s small footprint. and aptana studio in my regular home and office machines.

6. nano – yeah it is the latest editor that i use almost everyday. you know it is available in both linux and mac. so i use it frequently in my local dev platform (mac osx based) and remote machines (linux based). and it is much more easier than vi – i know vi(m) is a very good editor and there are millions of user of vi(m), so what? if i can’t find it useful then i wont use it :) – i find nano is very handy and easy to use. i have enabled php syntax highlighting in nano (via nanoarc) and it works really cool in shell :)

i dont like eclipse. there is no particular reason but for some unknown reason (i remember one, extremely resource hungriness and large footprint) i never feel comfortable with it. i use only one eclipse based ide (aptana) becoz there is no other good alternative to it. and only for this reason i also don’t use the new zend studio.

there are numbers of url shortening services available these days, including the good old tinyurl and something really short like u.nu. now when you get the short url shortened by using any of these services, you dont know where your browser is taking you! so if you are interested to figure out the original url hiding behind these short url, you need to have a little knowledge on how these services actually work. if you go to any of these short urls, they tell your browser “HTTP 30X: Object has moved” HTTP HEADER (optionally, some does it, some doesn’t) and then asks your browser to move to the original url using “Location” in HTTP HEADER. so all you have to do is just get the HTTP HEADER out first (PHP and Curl is pretty good at doing this, heh heh) and then parse the “Location” parameter from it.

Short URL: http://tinyurl.com/2dfmty
Original URL: http://ghill.customer.netspace.net.au/embiggen/

pretty interesting huh? if you analyze the full headers for each of these services you will find that most of them are using PHP in backend with Apache. only http://u.nu is using mod_rails (hence RoR) and bit.ly uses nginx :)

if you are interested in developing twitter applications, you must have read about twitter API and it’s authentication protocol. your application can fetch user’s private data but it has to authenticate itself as the user for that. so there are two ways to do it

1. asking user to provide his twitter username and password to your application (well, i am not interested to give away my PASSWORD to anyone!!!)
2. let twitter handle the authentication on behalf of you and ask user to grant permission to your application (hmm!! interesting)

now you see that #2 is more safe for your user. and i think most security concerned users will choose this way. so your application have to initiate this type of authentication system using twittter’s supported authentication protocol oAuth (it’s a commonly used authentication protocol used among number of popular service providers like yahoo, google and others)

now you see, pecl extensions are written in c and runs pretty faster. so i choose it without thinking much abt it. i have assumed that you know how to install a pecl extension in your php hosting and i am not going to blog detail about that right now. all that can help you right now is shell command “pecl install -f oauth” – you know, nothing talks better than command or code :)

after installing oauth extension in my hosting account, i start developing my twitter application. first i have to register my application with twitter. you can create your one by pointing your browser to http://twitter.com/oauth_clients/new. please remember that you have to provide a callback url which twitter use to redirect user of your application after a success/unsuccessful authentication. i will refer to that url as “callback_url” through out this blog post. my applications callback_url is “http://mydomain.tld/auth.php&#8221;

you will be going to use all of these in your application. now lets see how oauth works in brief. it initiate the talk using your consumer key and secret key. and then it request the “request token” from the service provider. if u r successful, you have to forward user of your application to the “authorize url” with the “request token”. now the service provider will ask to grant permission to your application from the user. if user grants (or disagree) the permission, the service provider (here, twitter) will forward your user again to the “callback url” of your application with a “new token”. now with the help of this new token and the token grabbed from previous “request token” your application will ask for “access token”. once you have the access token, you can authorize you application as the user itself with same privilege.

lets see how to do it in php with the help of oauth pecl extension. here we are going to initiate the talk, get the token and forward user to the service provider’s authorizing url.

you see that we are storing the oauth_token_secret of the “request_token” because we need it in our next step to fetch access token. in the example above i am storing it in flat file, but you will have to store it in db/file with proper index to the userid so that you can retrieve it later in our next step.

if user visit this page, he will be redirected to twitter authorize url and that may look like the following one with different app name.

now lets see how we handle if the user click “allow” or “deny” in the above page.

this is the callback file you specified in settings of your app [auth.php]

access token is the most important token for your application. there are two object in this token – one is “oauth_token” and “oauth_token_secret”. if you print_r the access token it will look like the following one (actual value is not shown here)

Array (
[oauth_token] => abcdefg
[oauth_token_secret] => uvwxyz
)

you have to store this access token for authorizing later as this user (the user that was visiting). using this token you can anytime authorize yourself as that user and fetch user’s data from twitter. so lets see how we can fetch user’s profile data in rss (or json) format. the REST API url to fetch this data is “http://twitter.com/account/verify_credentials.json&#8221;. you can find other important REST urls to fetch user’s timeline, public timeline and friends timeline (also update status) in twitter’s documentation of it’s REST API