OpenID for CodeIgniter made easy – All about it
Oct 21st
A few months back, I have been struggling to have openID authentication loaded to my application. It’s a hazard… the simple idea of having it integrated to my application and have users logged in using their existing facebook, google account is pretty fancy, but the code behind it is a mess, a complete tragedy. Luckily RPXNow stepped in and provided me a hand in authenticate people and handling the magic works. No one likes to reinvent the wheel after all, and this is a PRETTY HARD wheel to deal with…

Also, I’ve been exposed to the wonderful world of Codeigniter, and have found a wonderful library handling all the dirty works for me, (75% of those have been dealt with by RPXNow). All I have to do is have a small iframe in my view, and then deal with what I have to offer when I have successfully authenticated the users.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | function login() { $this->load->library('openidrpx'); // In the view, display an iframe pointing to the "embedurl" $this->load->view('loginview', array('embedurl', $this->openidrpx->EmbedUrl('start/openidverify')); } function openidverify() { $this->load->library('openidrpx'); if($token = $this->input->post('token')) { $data = $this->openidrpx->AuthInfo($token); if($id = OpenIDRpx::Identifier($data)) { // Authorize user! } } } |
However…
The idea is great, having some other web service do the dirty authentication work, and have a web framework ready library to do the integration dirty work… Having not to dirty your hands, but get things done. This is too easy to be true. But… I think using RPXNow is a bad idea, at least for me.
By using RPXNow, I am entrusting a third party site to deal with my users. There’s an extra hop in the process and thus, I am really relying on their service for my login process… What if they gone out of business for a while…?
Also, when the users login, the OpenID provider will direct them to yoursitename.RPXNow.com instead of your root website. Although RPXNOw offers ability to customize this hopping point, or with an extra cost ($20/month) to have it named as your root website (www.yoursitename.com). This serves to confuse your naive user even more.
By having a monthly fee, you can whitelist/blocklist certain provider, but this feature is not available in the free ones.
So!
It’s up to you, if you are really confident that you can deal with OpenID on your own, I suggest you do. But if you have absolutely no idea of how to even start looking at the problem, RPXNow is a definitive choice, it saves you “10 years of pain of extensive coding” and have your application up and running in under 2 hours (or less!!!). And if you like RPXNow and pay to be a loyal customer, you’ll gain a lot of extra functionality.
To be a web developer
Oct 17th
Is to know all of these <insert evil and sinister laugh here> languages. This post serves as a starting place for all who wants to be a web developer. You might not need to understand in depth on any of these, but the least is the basic. My choices of framework serves as a suggestion only, the real choice is yours.
1. HTML
Back to when internet was born and introduced to the naked world… Back to when the internet was young and needing a serious developer….Tim Berners-Lee said “let there be HTML”… and there was HTML, and it was good. The proof of its goodness stays ever since then until today. Yeah, every serious web developer use HTML. Easy to learn, easy to misuse. With great powers come great responsibility. So code well, and follow the standards.
2. CSS
HTML always comes with CSS. It helps you refrain from misusing those font and colors tag by having a separate CSS file. This serve as a way for you to separate content and display components. Also, helps you to hate tables and loves divs and spans. Though many would say otherwise…
3. Server Side scripting
When you have master your way of representing your thoughts on pretty html/css compliant documents, it’s time to deliver dynamic content. One problem though, is to choose which server side scripting you would go for. Unlike HTML/CSS where only 1 thing is required to learn and to have it beaten to your head. There are choices.
My Choice: PHP. Other choices: Ruby, Python, Java, ASP.NET
4. SQL
One choice again. SQL have become a parent of all database language. There are many database engine, most of them are built ontop of SQL or understand SQL anyway. So why bother learning a language that you might not be using. SQL is the way to go.
5. Javascript / Client Side Scripting
User interactivity is the heart of the website, make sure people enjoys reading your website. Javacsript has matured into a great way of delivering dynamic content by using AJAX interactivity. Facebook does it, most new website nowadays does it. Why don’t you?
6. Frameworks
Web developers have been reinventing the wheel so many times that they come up with a whole sort of different type of wheels. These framework give you the wheel and tell you how to use it properly with examples and screencasts… Save you tons and tons of time trying to imagine how the wheel would look like and how it will work.
There is no one type of wheel that helps all web applications. So there are a lot. Choose wisely for a server side scripting framework and a javascript framework.
my choices: PHP Framework: Codeigniter, CSS Framework: 960.gs, Javascript framework: Jquery or Mootools
7. Knowing your web server.
Tricks and tricks. Understand how to give your website optimum experience by deliver the webpage to them as fast as it could be. When you have become a master and reach new ceiling, it’s time to differentiate yourself.
Have FPDF integrate with CodeIgniter
Oct 16th
This is a simple, plug it in, it runs, guide. It is still highly recommended that you try and run FPDF successfully without Codeigniter first. So that you know how to actively runs it or your web server supports it.
Step 1: Download the Classes from the FPDF pages.
The fpdf.php in the Codeigniter directory.
The font directory in the fonts directory
Step 2: Config File
1 | $config['fonts_path']= "path-to-your-fontsdir/fonts/"; |
Step 3: Create the init_fpdf.php
1 2 3 4 5 6 7 8 9 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); if ( ! class_exists('fpdf')){ require_once(BASEPATH.'libraries/fpdf'.EXT); } $obj =& get_instance(); $obj->fpdf = new fpdf(); $obj->ci_is_loaded[] = 'fpdf'; ?> |
Step 4: Call it, use a controller to test
1 2 3 4 5 6 7 8 | $this->load->library('fpdf'); define('FPDF_FONTPATH',$this->config->item('fonts_path')); $this->fpdf->Open(); $this->fpdf->AddPage(); $this->fpdf->SetFont('Arial','B',14); $this->fpdf->SetY(30); $this->fpdf->Cell(40,10,'Hello World!'); $this->fpdf->Output('output.pdf','D'); |
Handpicked Handy PHP Libraries
Oct 15th
Do you ever wondering how to do certain things in PHP like generating graphs, generating pdf or parse RSS efficiently and easily. I found myself rewriting these codes every once in a while and was lucky enough to find these wonderful libraries/framework that are completely free and easy to use.
There are more, but I will only listed my handpicked best one out of these categories
RSS Parser
Normally I would use Jquery to do this stuff, but meh. When it comes to PHP, it’s all the way PHP
SimplePie: Very fast, easy to use, PHP driven RSS Parser
Demo | Documentation | Screencast (Yay!!)
I once used MagpieRSS for performance, but SimplePie offers a greater deal of functionality and when web servers are getting stronger days by days, the performance difference is not that big. One thing I love about this SimplePie is that it is actively being developed and actively updated.
Also, SimplePie got an integration with Codeigniter, my favourite PHP framework
Graph Generator
pChart: an Object Oriented framework that is capable of generating charts, graphs and best of all, it’s free. Data is grabbed from SQL Queries or CSV Files or just manually put them in.
Screenshots | Demo | Documentation (Very detailed!)
However, this library requires GD Library to be installed onto your web server and have PHP compiled with it. If you don’t have GD installed, better check for my second alternative: Libchart, a little bit old but suffice.
PDF Generator
FPDF: This little baby works splendid. It can stand alone or with zlib for compression and GD for GIF support.
It can be easily integrated with Codeigniter
Excel Generator
php-excel: very easy and fast way to generate excel spreadsheet using PHP on the fly
The approach is to convert a 2 dimensional array in PHP to a spreadsheet in Excel. However, because of it’s easy to use and fast performance, it does not have quite a few of features like cell styling, functions creating, sort…. If you need those (I don’t!), your choice is PHPExcel
Payment System
PHP-OpenID: for paypal, authorize.net and 2checkout (2CO). Yeah, the 3 most popular ones, who needs the lesser unpopular ones?
Checkout the links, it’s very detailed with code examples and all other stuff that you need to know. Scrap those you don’t need to know
This guy, Emran, is my hero by delivering this wonderful library to us
Introducing Codeigniter
Oct 10th
This is my first post about Codeigniter, a free MVC PHP framework that is very easy to understand and implement. I have been using Codeigniter for quite a while now and is very please with what I’ve achieved.
Hold on, what is MVC?
MVC is short for Model View Controller and is an abstract way of separating the logic, display and controlling decision. I wouldn’t go through defining them but for the sake of simplicity, I’ll throw in a simple example. And also, I’ll go through this example in Codeigniter’s way of talking, so that we won’t go to outer space without knowing it
Model is where the information is. View is how the information will be presented. Controller is which information to choose.
For example we want to view a page with the id of 3. we will have the controller called “view_page” and pass it an argument id = 3. The controller will then grab the information (page detail) by calling the “page” model and ask for page detail with the id of 3. After retrieving the page detail from the model, the controller would then call the “display_page” view and give it what to display.
In detail:
The Controller’s code will be:
1 2 3 4 5 | $id=$_GET['id']; $data=$this->page_model->loadpage($id); $this->load->view('page-display', $data); |
The Model’s code will be:
1 2 3 4 5 6 7 8 9 | function loadpage($id) { $data = db->query('SELECT * FROM page WHERE id=$id'); return $data; } |
The View’s code will be:
1 | echo $data['content']; |
If that’s not understandable, please, dig in to the framework and see what’s in there. Also, Codeigniter offered a 20 minutes video tutorial (oh, I love theses!) to quickly setup codeigniter and have a blog running in less than half an hour. Pretty impressive to me.
If you’d ever run into a wall, the user guide is always there to help you.
Have fun igniting codes