As part of a new project, I have created a quick and simple Twitter OAuth login system which can protect sensitive content with very little fuss.
Hosted on github, Twitter-PHP-Login will give your PHP site Twitter login functionality with only a few lines of code.
First you must register an app on Twitter at http://dev.twitter.com/apps to get your consumer key and secret.
- Callback URL must be the page on which you have your login button
- Application Type must be Browser
First, download the code with the following command:
git clone git://github.com/deanbarrow/Twitter-PHP-Login.git
Open twitter.php and insert your Twitter consumer key and secret. Set $home to match the directory structure you are using.
Now visit index.php in your browser, you should be prompted to login, after this you will be forwarded to protected.php. Try logging out then revisiting protected.php, you will not have access unless you are logged in.
To integrate the login system into your site, each page should have with the following:
To insert the login button, call twitterLogin(); anywhere on your page.
To protect a page, call twitterProtect(); at the top of the page.
To logout, call twitterLogout(); on your logout page.
Very quick and very simple. Please see the source code for additional instructions on how to modify the script to further meet your needs.