Archive

Archive for the ‘PHP’ Category

How To Debug PHP Using Firefox With FirePHP

July 15th, 2009

Typically, there are two main ways of debugging server-side code: you can utilize an Integrated Development Environment (IDE) with a built-in debugger or log and perform your debugging processes in a web browser.

10-01_debug_firephp_leading_image

This article shares an elegant, simple, and more maintainable way of debugging Ajax apps via the web browser (more specifically for the Mozilla Firefox browser). You’ll learn the basics of leveraging Firefox in conjunction with Firebug and FirePHP to implement FirePHP libraries on web apps and logging messages in the Firebug console.

A Brief Introduction

When Ajax techniques became popular, developers faced a new problem: how can we debug Ajax requests and responses efficiently for complex web applications? If using a debugger was hard enough with the RESTful model, triggering an Ajax-specific request is a pain and a bit more difficult; dumping logs and information pertaining to those Ajax operations had to be done using JSON or XML.

This is where FirePHP helps, allowing you to log your debugging messages to the Firebug console. FirePHP doesn’t mess with your code (and it doesn’t require you to modify anything to trap errors): the messages you print are sent to the browser in the HTTP response headers, which is great when you’re using JSON or XML since it won’t break their encoding.

This makes FirePHP ideal not only for debugging your Ajax requests, but also your entire PHP codebase.

So, what is FirePHP?

FirePHP is an add-on for an add-on: it extends the popular in-browser web development tool called Firebug with an API for PHP web application developers. FirePHP is free and easily attainable via the Mozilla Add-Ons section on the official Mozilla site. The official FirePHP site can be found via this web address: www.firephp.org. Christoph Dorn is the person responsible for creating FirePHP.

What Do I Need to Get Started?

As you might have guessed, you need three things to get up and running with FirePHP, they are:

  1. Firefox
  2. Firebug
  3. FirePHP

If you don’t have all of the above applications installed on your machine, click on their link to learn about how to download them for your particular system.

Installation of the three things above is a straightforward process. FirePHP can be a little tricky to install if you’ve just recently started learning about web development, but there’s good documentation out there about it.

This article is about using FirePHP, so I’ll let you handle the installation part (though feel free to ask in the comments - we’d be happy to help if you encounter issues).

A Couple of Tips

Once you’ve installed FirePHP, and included it in your web application, you are ready to debug and log data. But first, I’d like to share two helpful tips I’ve learned:

Tip #1: call ob_start()

Because the information is sent to Firebug in the HTTP Headers, you should activate the output buffering or you might get the "headers already sent error". It may sound complicated, but all you have to do is write ob_start() on the first line of your PHP script that you’re debugging.

Tip #2: don’t forget to disable FirePHP Logging when you go live

You have to disable FirePHP when the site goes live or you will risk exposing sensitive information to anyone that has Firebug/FirePHP installed (we’ll talk about how to do this later down the article).

And then just a general tip for Firebug/FirePHP users: it’s also a good idea to disable or suspend Firebug and FirePHP when you’re just browsing the web because they can really slow down some websites and web applications (such as Gmail, for example).

Getting Started with FirePHP Logging

This is the fun part where we start logging messages and reviewing the basic logging functions.

One thing to note is that, just like PHP, which (at least for PHP4 and PHP5) is a "pseudo object-oriented" language, you can use FirePHP in a procedural or object-oriented (abbreviated OO from now on) manner.

I prefer the object-oriented techniques and I encourage you to use the same pattern as it is considered the most popular and most modern approach to building apps.

The OO API allows you to instantiate a Firebug object to use it or to call its static methods directly. I’m a lazy guy and because static methods are more terse and require less typing, that’s what I use.

Instantiating the OO API Object

In your script, you can use the following code block to create the FirePHP object ($firephp).

require_once('FirePHPCore/FirePHP.class.PHP');
$firephp = FirePHP::getInstance(true);
$firephp -> [classmethod]
OO API with Static Methods

This is the format for calling static methods in your scripts.

require_once('FirePHPCore/fb.PHP');
FB::[nameofmethod]
The Procedural API

Here’s how to use FirePHP’s Procedural API:

require_once('FirePHPCore/fb.PHP');
fb($var)
fb($var, 'Label')
fb($var, FirePHP::[nameofmethod])

We will not get into any detail about the benefits and coding style of each API, I’ve included them here only so you see what options are available for you. In other words, I don’t want to start a flame war about which procedure is better - it’s up to you to decide and I’ve noted my preference.

Logging Messages and Information in the Firebug Console

Let’s talk about logging messages in the Firebug console (remember, this will only work if you’ve configured your app for FirePHP).

Examples of Basic Logging Calls

If you are ad-hoc debugging a bug, the following examples are what you’ll be interested in utilizing.

Fb::log("log message")

This will print a string that you pass to it onto the Firebug console. Using the above example results in the following message:

Log message.

Fb::log($array, "dumping an array")

Passing an array (no more for loops or print_r() in your scripts) outputs the content of your array. The above example will result in the following message in the Firebug console:

Dump message array

Tip: when you hover your mouse on logged variables in the Firebug console, an info window will appear in the web page containing all of its elements. It’s a nifty feature, don’t you agree?

10-05_variable-viewer

Logging an Information Message

Here is an example of logging information messages using the info method.

Fb::info("information")

This is the message it logs in your Firebug console:

          10-06_info-msg

Logging a Warning Message

Here is an example of logging a warning message.

Fb::warn("this is a warning")

This is the message it logs in your Firebug console:

          10-07_warning-msg

Logging an Error Message

Here is an example of logging a warning message using the info method.

Fb::error("error message")

Here’s what an error message looks like in the Firebug console:

          10-08_error-msg

Enabling or Disabling FirePHP Logging

When your site goes live, you can (and should) disable FirePHP logging. Call the following line of code on the first lines of your script.

FB::setEnabled(false);

What’s great about this is that you can leave all of your FirePHP code in your scripts for later use - just pass either true or false when you want to turn logging on or off.

If your application uses a "config file" to keep track of global settings, it is advisable to set a configuration option to enable or disable it.

Conclusion

First, here’s a screen capture showing all of our messages in Firebug all at once (I ran it sequentially).

10-09_console-demo

In this article, we covered the very basics of using FirePHP to help you debug and gain information about your PHP/Ajax applications easier and through the web browser. I hope that this results in you becoming convinced that you should explore your debugging options outside of "old-school" techniques such as using echo or print on top of your web page layout to see what a variable or array contains. Using FirePHP is so easy and convenient, and gives you much more options and data for debugging purposes.

In a future article, I’ll be covering more complex features of FirePHP and using Firebug to make this simple debugging tool a more robust and fully-featured logging framework.

admin Firefox, PHP , , ,

20 Promising Open Source PHP Content Management Systems

June 30th, 2009

Content Management System, or CMS is an application used to manage news easily so that users can publish, edit and delete articles from the back-end admin system. HTML and other scripting language are not necessary to operate a CMS, though having them will add more advantages.

Since we had looked into 22 open source PHP frameworks, i decided to do a roundup of 20 Open Source PHP Content Management Systems so that readers who don’t have strong PHP knowledge can easily create their website using free and open source CMS.

1. Wordpress

Wordpress is a powerful yet easy to use content management system. Initially it was designed as a blogging platform. However, it slowly become popular and can be customized into a powerful CMS with some tricks and plugins. I had wrote an article about Wordpress SEO plugins and also talked about things that you should know about Wordpress 2.8.

wordpress

2. Drupal

Drupal is a free and open source modular framework and Content Management System (CMS) written in PHP. It is used as a back-end system for many different types of websites, ranging from small personal blogs to large corporate and political sites.

drupal

3. Joomla

Joomla is an award-winning content management system (CMS), which enables you to build Web sites and powerful online applications. Many aspects, including its ease-of-use and extensibility, have made Joomla the most popular Web site software available. Best of all, Joomla is an open source solution that is freely available to everyone.

joomla

4. Frog CMS

Frog CMS simplifies content management by offering an elegant user interface, flexible templating per page, simple user management and permissions, as well as the tools necessary for file management.
frog

5. SilverStripe

SilverStripe is a PHP CMS built with Sapphire framework, and it uses MVC design pattern. you can view example sites that built with SilverStripe from the official webpage.
silverstripe

6. Mambo

Mambo is a full-featured, award-winning content management system that can be used for everything from simple websites to complex corporate applications. Although some Mambo sites had already migrated to Joomla, but i think i should include Mambo as it is still a great CMS.
mambo

7. TYPOlight

TYPOlight is a PHP 5 CMS and it has a lot of features such as live update, cross-browser CSS framework generator(IE7 compatible), templated based front end output, use Ajax and Web 2.0 technologies. You should check out the main page for more info.
typelight

8. Concrete5

Concrete5 is an open source content management system with simple administaror interface. You can edit a web page live by using the editing toolbar provided after you log in as administrator.
concrete5

9. Textpattern

Textpattern is yet another very popular content management system. It requires PHP 4 to run and has a lot of plugins that you can use for various customizations.
textpattern

10. Symphony

Symphony is a CMS that uses XML/XSLT as its templating language. Symphony lets you customize anything you like, from the website’s URL structure to your publishing environment. For a non programmer, this CMS might be complicated to learn.
symphony

11. MODx

MODx is both a PHP application framework and content management system. MODx is the first free PHP CMS to offer an API that fully supports Web 2.0 Ajax technology. It is SEO friendly CMS, and allows you to configure the meta content for each page.
modx

12. Habari Project

Habari is a highly recommended open source blogging platform. It is being written specifically for modern web hosting environment, and uses modern object oriented programming techniques.
habari

13. CMS Made Simple

CMS Made Simple is highly customizable and there are a lot of Modules for you to download. The Documentation is pretty complete and easy to follow.
cms-made-simple

14. ImpressCMS

ImpressCMS is a community developed Content Management System. It is highly scalable and is extremely useful for managing online communities.
impress-cms

15. Exponent CMS

Exponent uses an intuitive and flexible content editing system that allows website pages to be edited on the page as it is displayed. You can download modules and themes from the official website too!
exponent-cms

16. MiaCMS

MiaCMS is a fork of the Mambo CMS. It has a powerful and extensible third party entension system, and also a flexible site theming capabilities. MiaCMS supports OpenID and can consider to be a stable and mature CMS.
mia-cms

17. Jojo CMS

Jojo is a search engine friendly CMS. You will have SEO friendly URL to your article, and Jojo will handle www/non-www domains for you. Beside SEO friendly, Jojo also lets you extend the functionality by adding product databases, blogs, image galleries or whatever takes your fancy.
jojo

18. TYPO3

TYPO3 is a free Open Source content management system for enterprise purposes on the web and in intranets. It offers full flexibility and extendability while featuring an accomplished set of ready-made interfaces, functions and modules.
typo3

19. Elxis CMS

Elxis CMS comes with a lot of features such as Search Engine Friendly URL, strong security, adjustable member list and complete user profiles. Its automated tasks, modern design, AJAX technology and multi-lingual interface helps you be more productive.
elxis-cms

20. Chyrp

Chyrp is a lightweight blogging platform and it uses Twig as the templating engine. The documentation is quite complete and you can download a lot of useful modules from the main site.
chyrp

admin PHP , , , , ,

My Tiny TodoList | A simple open source todolist written in PHP and jQuery

May 19th, 2009

My Tiny TodoList is a totally free, simple open source todolist written in PHP and jQuery released from Max Pozdeev and based on my original MyToDoList application.

Using MyTiny TodoList you can add, modify or delete tasks, mark a task as completed and set task priority. Max improved a lot the interface with some nice jQuery effects and other general improvements. The result is very interesting and I suggest you to take it a look.

Max Pozdeev MyTinyTodoList Website
MyTinyTodoList Demo

 

Some screenshots:

todo1

 

todo2

 

todo3

Install My Tiny TodoList
1. Download, unpack and upload to your site.
2. If you want to use Mysql database instead of Sqlite - uncomment the line begining with $config['mysql'] in file ‘init.php’ and specify your settings as described in file.
Otherwise sqlite database file ‘todolist.db’ will be created in directory ‘db’. If no - create it manually and make it writeble for webserver/php.
3. Open in your browser file ‘dba.php’ from your site and create tables in databse.
4. Open ‘index.php’ in your browser to run the application.

admin PHP, jquery , ,

How to implement a Post-to-Wall Facebook-like using PHP and jQuery

May 18th, 2009

In the past months I received a lot of request to write a tutorial for beginners in order to explain how to implement a Post-to-Wall Facebook-like. So, I prepared this very simple example which helps everyone understand how to implement this feature in a website using just some lines of PHP and JavaScript code.

Take a mind, every post in the Facebook Wall contains a lot of information (user, sender, message content, date, number of comments, …):

facebook(1)

But how I said, this tutorial is for Ajax/jQuery/PHP beginners. So I decided to simplify the original Wall using just a single information: the message content.

In this tutorial we have these files:

- confing.php (database connection parameters)
- index.php
- insert.php
- jquery.js

How the Wall works?

 

facebook(2)

index.php contains a form with id "submit_form" with an input text with id "message_wall". When an user submits a new message. Then the new message is appends to top of the ul list with id "wall" with a nice fade-in effect (with jQuery). Ok, now take a look at the code.
1. index.php
index.php is very simple and contains just simple HTML code:

<form id="submit_wall"&gt;
<label for="message_wall">Share your message on the Wall</label>
<input type="text" id="message_wall" />
<button type="submit">Post to wall</button>
</form>
<ul id="wall">
</ul>

The <ul> list with id "wall" is the "container" of messages which are posted into the wall.

2. JavaScript Code
Open index.php and include jQuery in the <head> tag of the page:

<script type="text/javascript" src="jquery/jquery.js"> </script>

…then add this simple function to enable Ajax functionalities to insert the message posted from the user into a database table without reload the page:

<script type="text/javascript">
$(document).ready(function(){

$("form#submit_wall").submit(function() {
var message_wall = $(’#message_wall’).attr(’value’);
$.ajax({
type: "POST",
url: "insert.php",
data:"message_wall="+ message_wall,
success: function(){
$("ul#wall").prepend("<li style="display: none;">"+message_wall+"</li>");
$("ul#wall li:first").fadeIn();
}
});
return false;
});
});

</script>

.prepend(…) is a jQuery function to insert elements inside, at the beginning, of a specific element (in this case UL list with id wall –>$("ul#wall")). When the new message is added into the list is hidden (display:none). Then it appears with a fade-in effect:

$("ul#wall li:first").fadeIn();

ul#wall:first: gets the first li element (the last added) into the ul list with id "#wall".

3. insert.php
insert.php contains some lines of PHP code to insert the new message into a database table. In this example I created a table WALL with just one attribute "message". PHP code is very simple:

<?php
if(isset($_POST['message_wall'])){
/* Connection to Database */
include(’config.php’);
/* Remove HTML tag to prevent query injection */
$message = strip_tags($_POST['message_wall']);
$sql = ‘INSERT INTO WALL (message) VALUES( "’.$message.’")’;
mysql_query($sql);
echo $message;
} else { echo ‘0′; }
?>

admin PHP, jquery , ,

Peeling a Hand in Photoshop

March 18th, 2009

Today we’re going to demonstrate how to peel a hand in Photoshop. You can use this technique to peel other objects of course. This is the final image preview..

 

Today

Step 1

 

Let’s get started, first download this picture of an open hand. You can use any other if you want to. Start extracting the hand from the background and pasting it into a new document, 1280 x 1024 pixels. Then create a new Black Fill Layer below “Hand” layer.

Step 2

Now, what we need is to make all the fingers larger. Using the Lasso Tool, select only the thumb on “Hand” layer, then press V key to activate the transform options and distort the thumb a little bit, you can Command (Ctrl) - Click one of the selection corners and transform the shape.

Step 3

With the Clone Stamp Tool fix the distortions on the finger, also Erase the bad areas.

Step 4

Repeat the same process than step 2, but this time select the rest of the fingers, distort them and fix the details.

At this point you must have a nice hand with long fingers. Now it’s time to start the peeling process.

Step 5

Duplicate the “Hand” layer, hide the original for a while and then adjust the Hue / Saturation values of “Hand copy” layer, set Saturation: +20 and Lightness: -40.

Step 6

Now select “Hand” layer on Layers palette and go to Layer > Layer Mask > Reveal All.

Step 7

Now start peeling, select a 20px brush (Hardness 100%), set a black foreground and start painting on the hand’s layer mask.

Step 8

Paint more stripes on hand’s layer mask across the finger.

Step 9

Now select “Hand copy” layer and apply to it a Layer Mask > Reveal all.

Step 10

On “hand copy” layer mask, paint some black stripes. Check the tiny red circles, those will be the visual join points between the two hand layers.

Step 11

Repeat the previous steps as many times as needed, try to get something like the images below. Remember, take care of the join points because those will give realism to our design.

Step 12

Now repeat the peeling on all other fingers, wrist and palm.

Step 13

Then select the Burn tool, set the brush to 20px Hardness 0% and Exposure to 50%. And paint over “Hand copy” layer, burn all the areas next the joins. Burn some areas of “Hand” layer aswell.

Step 14

To improve the torn sensation select the Dodge Tool, set an irregular brush and paint on “Hand” layer edges.

Step 15

Burn with a huge brush, the palm and fingers on “Hand copy” layer, also Burn the fingers and palm of “Hand” layer to increase the deep sensation.

Step 16

We’re close to finish. After burning here and there you should have something like this.

Step 17

Now, draw a Radial Gradient background below “Hand” layer, use these colors (#996938 - #000000). Then change the “Gradient” layer Opacity to 35%.

Step 18

These are optional steps. Create a new layer above “Hand copy” layer and name it “Red Veins”. Then with the Pen tool (just the paths), draw lines across the fingers. Then select a red Brush (Hardness 100%), hit the A key, then Right click (or Control Click on a Mac), click on Stroke Path option, select Brush - Simulate Pressure and then OK, do the same for all the fingers.

As an additional detail, just Burn some shadows over the “Red Veins” layer.

Finally Repeat this step but with “Blue Veins” this time.

Step 19

Now apply the following layer styles to “Veins” layers.

Final result

And that’s it! just try peel another stuff, or add more interesting things inside a peeled object. Good luck!.

DOWNLOAD PSD FILE

Feel free to post links and examples of stuff you peeled and leave us some feedback. Thanks…

admin PHP, Photoshop , ,

Internet Explorer 8 Release Candidate 1 Ready

March 17th, 2009

A near-final version of Microsoft’s Internet Explorer 8 was made available for download today. The free browser is only available for users of Windows Vista, Windows Server and Windows XP with Service Pack 2 installed. Microsoft has been steadily improving Internet Explorer 8 which has been in development for a few years with Beta 1 and 2 versions of the browser being released in March and August last year respectively.

 

iternet-explorer

 

Although still the most dominant web browser Internet Explorer has seen it’s market share slowly being chipped away by Mozilla Foundation’s Firefox web browser and with Google’s recent and swift entry into the market with Chrome.

admin Ajax, Html, Javascript, PHP, Web Design, Web Development, Web2.0

eXTReMe Tracker