Archive

Posts Tagged ‘PHP’

How To Debug PHP Using Firefox With FirePHP

July 15th, 2009 No comments

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.

20 Promising Open Source PHP Content Management Systems

June 30th, 2009 No comments

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

Open Source Spell Checker Application

May 27th, 2009 No comments

Spell Check Rex is an Open Source Spell Checker Application. It’s a Free spell checking program, written in PHP and MySQL, that can be installed on your website to regularly monitor and report on spelling mistakes. This should be particularly important for e-commerce sites, sites with dynamic content, and generally for people who want their sites to present positively.

It supports frame-enabled websites & directories, pages can be excluded. This Free Application spiders the  site it is installed on and generate reports. These reports are then provided both on-screen and via a download-able report.

open-source-spell

Spell Checker Features

 

  • Free Application as most spell checking services charge money
  • Fully built-in to your website meaning you have control. No 3rd-party required.
  • Open source (GPL/GNU). You can see and modify the code.
  • Schedule regular reports to be emailed to you
  • Highly configurable: exclude directories, customize data, set crawl limits/behaviour
  • Comprehensive word list (approximately 115,000 words)
  • Locale-aware spellings
  • Multi-language admin panel
  • Free support available
  • Only 2.5mb download

Admin panel has multilingual support but Spell Check Rex can only spell check English written websites.

7 Free & Powerful File Managers using Ajax/PHP/JS

May 21st, 2009 No comments

If you are looking for a powerful file manager ready to use in your web projects and simple to customize, take a look at this list with the best and free file manager currently in circulation. Some of these file managers support PHP only or javascript only or Ajax that will give you powerful tool to easily browse directories & files on the server, search, upload and download files, edit, copy, move, delete files and more.

If you know other interesting resources about this topic please leave a comment!

1. AjaXplorer

ajaxplo;rer

AjaXplorer is a free Ajax file manager with an easy-to-install file explorer for remotely managing files on a web server. Its “rich client” layout and actions make it accessible to any end-user for a variety of purposes: file management/sharing, photo gallery, code browsing, etc. Only PHP (4 or 5) is necessary, no database needed.

  • Rename/Copy/Move/Delete/Download files or folders
  • Upload multiple files and track status with progress bar (Flash required and no https)
  • Create folders and empty files
  • Edit Text files and code files (js, php, html, java, sql, perl), syntax is highlighted in the editor
  • View Images online, preview images in the list, diaporama of a given folder
  • Listen to MP3sonline without downloading them
  • View Flash videos (FLV) online and full screen.
  • Browse and Extract ZIP files online

2. fileNice

filenice

fileNice is a free php file browser, particularly useful if you have a ‘dump’ folder on your server where you regularly upload files and you want to be able to see what’s there.

3. File Thingie

file fthings

File Thingie is a small web-based file manager written in PHP. It is intended for those who need to give others access to a part of their server’s file system when FTP is not practical. Through File Thingie you and your users get access to the most common functions:

  • Simple — Just one file
  • Upload multiple files at once
  • Multiple users and user groups
  • Create subdirectories
  • Rename, move, delete and copy files and folders
  • Search for file and folder names
  • Control access to files based on black- or whitelists
  • Edit text files
  • Unzip files without downloading
  • Easy customization of the CSS based layout
  • Translate into your own language

4. MooTools based FileManager

MooTools1

A MooTools based File-Manager for the web that allows you to (pre)view, upload and modify files and folders via the browser. Features include:

  • Browse through Files and Folders on your Server
  • Rename, Delete, Move (Drag&Drop), Copy (Drag + hold CTRL) and Download Files
  • View detailed Previews of Images, Text-Files, Compressed-Files or Audio Content
  • Nice User Interface
  • Upload Files via FancyUpload (integrated Feature)
  • Option to automatically resize big Images when uploading
  • Use it to select a File anywhere you need to specify one inside your Application’s Backend
  • Use as a FileManager in TinyMCE

5. Relay

realy

Relay is a wonderful piece of ajax code written with the aid of the prototype ajax toolkit. It does a wonderful job of uploading / downloading and managing files on your private server, let’s check out some of its features:

  • drag-n-drop files and folders
  • dynamic loading file structure
  • upload progress bar
  • thumbnail view, including pdf
  • multiple users & accounts

6. CKFinder

ckfinder

CKFinder is a powerful and easy to use Ajax file manager for web browsers. Its simple interface makes it intuitive and quick to learn for all kinds of users, from advanced professionals to Internet beginners. Let’s check out some of its features:

  • Folders tree navigation: intuitive for all users.
  • Quality image thumbnails, making it quick to find things.
  • Multi-language support with automatic user language detection.
  • Sensitive context menus for files and folders.
  • Full user control : create, rename and delete folders and files.
  • Full developer control: all features can be precisely configured with a powerful ACL and user roles system.
  • Lightweight interface.
  • No page refreshes: quick responses.
  • Secure file uploads: all uploaded files are checked according to the rules set by the developer.
  • Full source code included for the server side integration.
  • Instant integration with FCKeditor

7. eXtplorer

eXtplorer

eXtplorer is a web-based File Manager. You can use it to. Features include:

  • browse directories & files on the server and
  • edit, copy, move, delete files,
  • search, upload and download files,
  • create and extract archives,
  • create new files and directories,
  • change file permissions (chmod) and much more…
Categories: Programming Tags: , ,

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

May 19th, 2009 No comments

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.

Categories: Programming Tags: , ,

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

May 18th, 2009 No comments

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’; }
?>

Categories: Programming Tags: , ,