CodeIgniter 2.0 Is Baking

March 12th, 2010 | Save to del.icio.us now(0)

Just when I was loosing all hopes about CodeIgniter, yesterday EllisLab announced about their move to assembla and mercurial, in that there was a small but significant news about CodeIgniter 2.0.

A quick look into the change log revealed

PHP 4 support is deprecated.  Features new to 2.0.0 may not be support PHP 4, and all legacy features will no longer support PHP 4 as of 2.1.0.

This is what I was waiting for. What it means, as pointed by Phil Sturgeon and Elliot Haughin, is that CI 2.0 will not run on PHP 4, but more importantly, it can now take full advantages of PHP 5.

One other thing that I liked is

Added ability to set "Package" paths - specific paths where the Loader and Config classes should try to look first for a requested file.  This allows distribution of sub-applications with their own libraries, models, config files, etc. in a single "package" directory.  

Which means that now we can create common area where we can keep helpers, views and libraries that needs to be shared between two applications.

While there are many more updates these two got me excited.

For now let’s wait for them to release, meanwhile you can sign up for Bitbucket and follow the updates for CodeIgniter Project.


(Search web development related contents)

How to get Latitude/Longitude from an address (or Geocoding ) using PHP

March 10th, 2010 | Save to del.icio.us now(0)

While Google’s documents for maps API does good job in showing how to get lat/long from an address in JavaScript they do not really show any example of doing the same with PHP.

 

So to make you life simple here is a small script in PHP that does that.

 

 

$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address=573/1,+Jangli+Maharaj+Road,+Deccan+Gymkhana,+Pune,+Maharashtra,+India&sensor=false');

$output= json_decode($geocode);

$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;

 

The line above makes a request to Google maps API. Passes the address, and receives the response in JSON format.

The URL has following options

http://maps.google.com/maps/api/geocode/output?parameters

where output can be 1) JSON or 2) XML

For more details about parameters check out the Google’s geocoding documentation.


(Search web development related contents)

Where is MySQL Gone Away?

November 11th, 2009 | Save to del.icio.us now(0)

Last Sunday I got to work on a very interesting problem in WordPress which I initially thought could be solved in like 5 mins, but alas it took me almost 7 hours before I found and fixed the problem.

Let me describe the problem, I was running a simple xml parsing script whose task was to parse the xml file and insert the content into WordPress database as a post, everything was working fine except the ‘INSERT’ statement was failing with out any errors. Basically everything would run but nothing would get inserted into database and no errors. We had used the ‘wp_insert_post’ function in  ‘post.php’ file to handle the insertion of post, which was returning ‘0’ instead.

After lot’s of time spend checking and cross checking the sql statements for error and PHP code logic, i finally found the problem which was a small kinda cryptic error ‘MySQL server has gone away’ for every single query that was getting executed in the script.

Well, a quick google search took me to MySQL manual page where it list bunch of possibilities on why the error might be coming.

To me the most logical one were

    1. You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.
    2. A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.
    3. You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the reconnect flag in the MYSQL structure is equal to 0).
    4. You can also get these errors if you send a query to the server that is incorrect or too large.
    5. You are using a Windows client and the server had dropped the connection (probably because wait_timeout expired) before the command was issued.

I investigated each one but it turned out that because a query was taking a bit to long to execute MySQL closed the connection and refused all further request from the client.

So you might be wondering what was the Solution to this problem.

Well Rob of Rob’s notebook had the almost perfect solution for it. He created a replacement file for ‘wpdb.php’ which takes care of this problem, yeah it is temporary and you have to remember to replace this file every time you do an WordPress upgrade but it works.

If you are facing this problem go download it and replace you ‘wpdb’ file and save yourself some time.

Check out PHPCamp.net a article sharing website relevant to our own PHP community

(Search web development related contents)

Integrating With Twitter API In CodeIgniter

January 29th, 2009 | Save to del.icio.us now(0)

I needed to integrate Twitter API in one  of my web applications which uses CodeIgniter framework.

 

As their is no direct library available in CI for twitter integration, at first go this might look very difficult, but it is really simple.

 

Here is how you can do it..

  1. First download the  Twitter class for PHP.
  2. Put the class.twitter.php file in application/libraries folder.
  3. Rename class.twitter.php to twitter.php ( to make it compatible with CI naming conventions).
  4. Open twitter.php file and set following variables
var $username=’'; //twitter username
var $password=''; // twitter password
var $user_agent=''; //an identifier for twitter preferably email address
Are you satisfied with your knowledge? No, then spent 15 minutes every day on PHPCamp.net a knowledge sharing website for our own PHP community

If you have followed these steps your integration is almost complete, now all you need to do is use the twitter library, here is an example to get you started :)

 $this->load->library('Twitter');
 $msg=’Just Integrated Twitter with CodeIgniter ’;
 $this->twitter->update($msg);

By the way you can follow me on twitter @thecancerus.


(Search web development related contents)

Debugging PHP using Xdebug and Notepad++ : Part I

January 25th, 2009 | Save to del.icio.us now(0)

I am sure all of you have used ‘echo’ and ‘print_r’ to debug PHP.

We all know that this way debugging is hard and you need to remember to remove them from production server.

Well, thanks to xdebug you can now debug, and you don’t need expensive or blotted IDE for that, just plain and simple Notepad++ can do the job.open php.ini in wamp

In this post we will setup xdebug and DBGp plugin with Notepad++.

Let’s start by installing xdebug.

  1. Download the latest release of xdebug for PHP version you are using.
  2. Copy xdebug dll file into php’s extension directory, in my case, as I use wamp, it is c:\wamp\php\ext .
  3. Now we need to configure xdebug so that it get recognized by PHP, so open php.ini
  4. Add following at the end of your php.ini file
    [xdebug]
    zend_extension_ts="c:/wamp/php/ext/php_xdebug-2.0.3-5.2.5.dll"
    xdebug.profiler_output_dir = "c:/wamp/tmp/xdebug"
    xdebug.profiler_output_name = "cachegrind.out.%p"
    xdebug.profiler_enable = 0
    xdebug.profiler_append=0
    xdebug.extended_info=1
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    xdebug.idekey=xdebug
    xdebug.remote_log="c:/wamp/tmp/xdebug/xdebug_remot.log"
    xdebug.show_exception_trace=0
    xdebug.show_local_vars=9
    xdebug.show_mem_delta=0
    xdebug.trace_format=0
  5. Just create a folder ‘xdebug’ in ‘c:\wamp\tmp’ folder.
  6. Finally restart Apache service .

With these steps you have, finished xdebug installation, it is configured for profiling application and remote debugging. Check documentation to know what all these configuration do, and tweak according to your preference.

Continue reading »


(Search web development related contents)

PHPCamp in Pune Mirror

September 3rd, 2008 | Save to del.icio.us now(0)

camping to connect

News about PHP and PHPCamp was published in today’s Pune Mirror.

Their is just one mistake though, MySpace[:( ]  is not in PHP. It’s my mistake, I conveyed the wrong information while disscussing[i still can't figure out from where 'myspace is in php' came to my mind] with reporter, stupid me :( .

I regret not saying Yahoo Answers or Wikipedia as an example instead of MySpace.


(Search web development related contents)

Easy File Uploading Solution For PHP

September 1st, 2008 | Save to del.icio.us now(0)

Uploading files/images is a task that is required in almost all web applications.

While uploading file is a very simple task, still lot of beginners in PHP get stuck in this step. So in this post I decided to share the functions I learned while I was a beginner, and I still continue to use them because of it’s simplicity and usefulness.

For all my file uploading needs I use the class.upload.php written by Colin Verot. Ok, I know all about PHP functions like move_uploaded_file() and is_uploaded_file(), still I prefer to use class.upload.php file because, this file provides me with good set of image manipulation functions along with a neat way to know when a file has been uploaded.

So, let’s get started on, how to easily upload a file in PHP.

First, let’s create a simple HTML form for uploading files.

 <form action="file-upload.php" method="post" enctype="multipart/form-data">

  Upload file: <input type="file" name="fileupload">

                  <input type="submit" value="save">

 </form>

It is important to note that the form’s enctype is  multipart/form-data. This a place where novice developers make lot’s of mistake, they will forget to add enctype attribute to form and them spends hours thinking why they are not able to upload files or images.

Now, that we have a form to upload files, let’s see how we can handle file uploads on server.

I am going to cover four scenario’s here.

Continue reading »


(Search web development related contents)

Fix ‘Blank page’ problem aka White Screen of Death

August 24th, 2008 | Save to del.icio.us now(0)

This is another interesting problem that baffles the novice PHP programmers.

We make a quick change, and upload the file to webserver, we access the webapge and your are presented with a blank white page, aka ‘white screen of death’. It does not even show any error message.

We end up thinking what happened, we refresh the webpage but usually nothing changes.

Why this happens?

This happens because your host has switched off error reporting(for good reasons). So whenever their is a fatal error in your PHP script, and you have error reporting turned off you are presented with white screen of death.

Continue reading »


(Search web development related contents)

Enable Your Joomla To Write In Hindi, Marathi, Bengoli, Gujarati, Malyalam, Telugu and Punjabi

August 20th, 2008 | Save to del.icio.us now(0)

UPDATE: This article is compatible only upto Joomla 1.5.12. I will make it compatible to latest version of Joomla as soon as i have time. Thank you.


Recently I was required to give a presentation to an agricultural college, they wanted to create a website for their college in Marathi, which resulted in akIndicPlugin for tinyMCE as Joomla uses it as default editor.

Here is how you can enable Joomla to write in Indian languages.

Step 1:Install akIndicPlugin for tinyMCE

Upload files to webserver,

  • Download the akIndicPlugin
  • Extract the archive using winzip etc. in a folder named akindicplugin
  • Now FTP the akindicplugin  folder and all files inside it, to “plugins\editors\tinymce\jscripts\tiny_mce\plugins” in case of Joomla 1.5.x or “mambots\editors\tinymce\jscripts\tiny_mce\plugins” in case of Joomla 1.0.x, using Filezilla.

Modify the ‘tinymce.php‘ file

  • Open tinymce.php file in “editors\tinymce” in  Notepad++ or your favorite editor.
  • In Joomla 1.0.x find $buttons2     = implode( ‘, ‘, $buttons2 ); or goto line number 250. In case of Joomla 1.5.x  find $buttons2[] = ‘forecolor’; or goto line number 190.
  • Add following lines at specified line numbers
$plugins[]            = 'akindicplugin';
  $buttons3[]            = 'akindicplugin';
  • Save the file, and upload to webserver.

Once you are done, login to Joomla administrator panel and check tinyMCE, if you see a button on tinyMCE toolbar, Congratulations! you have finished the first step.

akIndicPlugin for tinyMCE in joomla

Continue reading »


(Search web development related contents)

Solution To Session Timing Out Intermittently

July 21st, 2008 | Save to del.icio.us now(0)

A month back I had written about why your session might not be setting, even though you had set every thing as per the book. This time I am writing about a new problem that I faced with sessions.

The Problem

I recently faced a problem, where for some reason website would not remember session data for some users. They Log in, get to the home page, but the moment they click any other link they are logged out and taken back to login page.

Interesting thing is, this happens for both Firefox and Internet Explorer.

When I used the users credentials I was able to log in perfectly on my machine. When I passed him my credentials to try, and it failed on his machine.

I have faced this problem with both Joomla and Codeigniter framework.

Initially we thought it would be a problem with  just his browser’s cookie setting, so we got him to reduce the web browsers security setting to low, So that it allows for cookie acceptance.  As it turns out, it was not the problem with cookies either. Continue reading »


(Search web development related contents)