Simply Program

Simply programming - It’s a life style

Archive for November, 2007...

Filed under Programming, PHP

Well, here I was again doing a fast freelance job for a friend - He wanted a full functioning forum up and ready to go as fast as possible. I of course thought of the very nice free system - phpbb(http://phpbb.com). To make things interesting we had already put in place a custom made membership system, the phpbb forum would now have to integrate into our Registration and Login process seamlessly.

My first instinct was to go to the boards on PHPBB and do a quick search to find my solution - It turns out the solution is not fully laid out... Or atleast to me it didn't seem to be layed out.

So after about 30-45 minutes looking over threads and replies I decided to just look at how PHPBB initiated its sessions and cookies and go for it myself.

Here are my easy steps to accomplish this login / registration task (I have no error checking/hack prevention in place for my example, I don't want to do everything for you now :) )

STEP 1 - REGISTRATION

CODE:
  1. //Query to select the max number of users in the table
  2. $sql = "SELECT MAX(user_id) AS total FROM phpbb_users";
  3. $select=mysql_query($sql);
  4. $row=mysql_fetch_array($select);
  5.  
  6. //Taking the max number of records and adding 1 for the next user_id
  7. $user_id=$row['total']+1;
  8.  
  9. //Query to insert the basics into the users table.
  10. //NOTE - Take validation into your own hands, this is just an example.
  11. $sql = "INSERT INTO phpbb_users (user_id, username, user_regdate,
  12. user_password, user_email,user_active)
  13. VALUES ($user_id, '$username',".time().",'$password','$email','1')";
  14.  
  15. //Insert the user
  16. $insert=mysql_query($sql);
  17.  
  18. //Setup the users group so he/she has posting ability.
  19. //Why group_id=3?
  20. //On a basic PHPBB installation:
  21. // ID #1 = Visitor/Guest
  22. // ID #2 = Admin
  23. // ID #3 = Basic registered user
  24. //If you have a custom user group setup,
  25. //replace 3 with the id number.
  26. $group_id=3;
  27.  
  28. $sql = "INSERT INTO phpbb_user_group (user_id,
  29. group_id, user_pending)
  30. VALUES ($user_id, $group_id, 0)";
  31.  
  32. //Insert user into the correct group.
  33. $insert=mysql_query($sql);
  34.  
  35. //Add in your own registration for your own website here.

STEP 2 - LOGIN

CODE:
  1. //Place this on top of your login script
  2.  
  3. define("IN_LOGIN", true);
  4. define('IN_PHPBB', true);
  5.  
  6. //Be sure to update the root path to match your forum settings
  7. $phpbb_root_path = './forum/';
  8. include($phpbb_root_path . 'extension.inc');
  9. include($phpbb_root_path . 'common.'.$phpEx);

While checking for the username/password within your own system (and succeeding) enter these few lines of code.

CODE:
  1. $select=mysql_query("SELECT * FROM phpbb_users WHERE username='".$username."'");
  2. $row=mysql_fetch_array($select);
  3. $userdata = session_pagestart($user_ip, PAGE_LOGIN);
  4. $session_id = session_begin($row['user_id'],
  5. $user_ip, PAGE_INDEX, FALSE, $autologin, '0');

The above peace of code will use PHPBB's own session handler to create the cookies / sessions needed to log the user into the forum - as well as your own system.

Enjoy!

Comments (0) Posted by sp on Tuesday, November 13th, 2007

Filed under Programming, AIR

Adobes Apollo project has been provided a new breath of life, which so conveniently is named AIR (Adobe Integrated Runtime). Yes, the AIR project is the same as Apollo just with a few new (advanced) features.

The key feature to Apollo/AIR is the runtime enviorment as it allows you to take your Javascript, HTML, Flash, or Flex application and turn it into a light desktop application.

Why do I say "light"? Frankly, the AIR runtime does not handle its resources and memory access very well - hence any large system seems clunky, and slow to response.

Now, what can a light application do? What is the Runtime useful for at this stage in the game?

Lets take a real world example - Pownce.com...
"You can access all of your Pownce notes just on our website or you can download a small program for your computer.

The software is available right now for Windows and Mac users and will be available for Linux soon too. It takes advantage of a new technology from Adobe called AIR, which is super useful."

Screenshot

View larger image

Yes... Pownce has created a very simple IM type application and integrated it to work directly with their website.

Now, however cool this might be - Is it really practical to have another system like this? I personally believe not, Pownce will not steal any facebookers just because they have a cool AIR application.

In my opinion the largest contribution this runtime offers is the ability to instantly update your users / members of new content on your website. Imagine your user having an instant notification sent right to their desktop when a user has posted a reply to their topic? Many of you will say... so... thats email? Not exactly, when it comes to automated responses email has some flaws.

Over all AIR is not fully operational, its real world examples and applications are more experiments / cool toys instead of practical applications.

I do however believe this will be quite revolutionary and will more then likely become an effective way to deliver fresh content to your users as well as communicate your users content with your website(Instant desktop updates without c++!).

More to come as I am now developing a few "Practical" applications for my employers.

RESOURCES

Adobe AIR
Adobe Showcase
O2Apps.com

Comments (0) Posted by sp on Sunday, November 11th, 2007