I was struggling to check session expiry for Zend_Auth and redirect the users to login page with certain message to let them know the session has expired. Found following code to limit the session expiry time:

$authns = new Zend_Session_Namespace(Zend_Auth::getInstance()->getStorage()->getNamespace());
$authns->setExpirationSeconds(60 * 15); // for 15 minutes

Then the major problem that I encountered while setting the messages using Flash Messenger plugin. Though I am not quite experienced Zend programmer but since last couple months, I had used the Flash Messenger plugin directly from within action controllers. It seems the plugin is automatically loaded in the action controllers. But I was about to check the user’s login session expiry in one of my own custom plugin which extends Zend_Controller_Plugin_Abstract as follows:

class FHF_Acl_AccessCheck extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        /**
         * @author Raju Gautam
         * Check login session and throw some message for expiry
         */
        $hasIdentity = Zend_Auth::getInstance()->hasIdentity();
        if(!$hasIdentity && $module != 'user' && $controller != 'user' && $action != 'login'){
            // set some message and login form
        }
    }
}

Where I have checked if the the Zend_Auth has null identity and show/load the login form with some message. But while setting the message first I tried:

$this->_helper->FlashMessenger->addMessage(array('error' => "Session expired, please login again !"));

But this did not worked, threw error message instead.

So I researched then found in one of the pages in the internet and found the following solution:

class FHF_Acl_AccessCheck extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        /**
         * @author Raju Gautam
         * Check login session and throw some message for expiry
         */
        $hasIdentity = Zend_Auth::getInstance()->hasIdentity();
        if(!$hasIdentity && $module != 'user' && $controller != 'user' && $action != 'login'){
            $flashmessenger = Zend_Controller_Action_HelperBroker::getStaticHelper ( 'FlashMessenger' );
            $flashmessenger->addMessage (array('error' => 'Session Expired ! Please login again !'));
            $request->setModuleName('user')
                    ->setControllerName('user')
                    ->setActionName('login');
        }
    }
}

So if anyone wants to set the flash messages from outside of the action controllers, then you should use something like this using Zend_Controller_Action_HelperBroker class and its static helper getStaticHelper.

$flashmessenger = Zend_Controller_Action_HelperBroker::getStaticHelper ( 'FlashMessenger' );
$flashmessenger->addMessage (array('error' => 'Session Expired ! Please login again !'));

With this, you can get any plugin outside of the action controllers.

Hope this will help others struggling for the same.

Good luck!

Thanks.

phpMyAdmin is the mostly used web based PHP application for MySQL client. When we use it in the local systems, we always need to enter username and password to login. To avoid prompting the login screen you need to overwrite the existing settings with our own. phpMyAdmin lets us to overwrite the settings/configurations by using a file in the root of its directory.

A file is always delivered named config.sample.inc.php in its root. You just need to rename it to config.inc.php and change the following line:

$cfg['Servers'][$i]['auth_type'] 	= 'cookie';

to

$cfg['Servers'][$i]['auth_type'] 	= 'config';

And add the following two lines:

$cfg['Servers'][$i]['user']         = 'root';
$cfg['Servers'][$i]['password']     = 'asdf#asdf'; // use here your MySQL password

Hope this helps someone who is willing to avoid login screen in phpMyAdmin.

Cheers !

If anyone of you trying to import some data from CSV directly into MySQL database, always use LOAD DATA LOCAL INFILE command. It is quite faster and easier to import lots of data within few seconds even more than 25MB of CSV data.

The syntax for the command can be found in details at http://dev.mysql.com/doc/refman/5.1/en/load-data.html but the simple one would be something like below:
> Login to the MySQL server first i.e. mysql -h localhost -u root -p (And give the root password).
> Use the specific database i.e. use .
> The run the following command:
LOAD DATA LOCAL INFILE "/path/to/csvfile.csv" INTO TABLE
FIELDS TERMINATED BY "," LINES TERMINATED BY "\n" (field1, field2, field3, field4, fieldN);

Note: Remember the fields should be exactly same as number of columns in the CSV.

The used command is not allowed with this MySQL version

This problem makes crazy and I had spent around 4 hours (half of the working day) to fix it. I was on Ubuntu 12.04 LTS and I was not sure where exactly to look into for this to fix. I tried to look at my.cnf but could not find anything out there. Actually this problem comes when the flag/setting “local-infile” is disabled.

First solution would be to add the following on the my.cnf itself:
[odbc]
local-infile=1

Or Secondly you can simply enable it while logging into the MySQL server.
> mysql --local-infile=1 -u root -p

Then run the above LOAD DATA LOCAL INFILE… command and it will work like a charm and you will get all the data from CSV to your MySQL database table.

Hope this helps you !

Today I was integrating MageBridge to work with Joomla and Magento together. The MageBridge stand alone was never a problem for me as I have been doing this in couple of other projects as well.

This time I had a little different where Magento has one very popular and useful module used called OneStepCheckout which gives a single page while checkout with all the available & required options in it. Normal process is working quite fine except one. There is feature in OneStepCheckout that already existing customer can login by clicking in a link called “Already registered? Click here to login.”. This was not working anymore when I browse the Magento from Joomla through MageBridge.

MageBridge has a good and almost precise tutorial on this as Using OneStepCheckout with MageBridge. As stated there under “Getting the JavaScript right” as “Also, make sure to configure a MageBridge Custom Block module that displays the block before_body_end. It is best to add a new Joomla! module position to your template just before the tag to add this module to.”

We should add custom block module in Joomla positioned at the end of the template page or i.e. just before the closing body tag.

So I added a module position mbbeforebodyend in the template at the end of the template page as:




And then added the MageBridge’s custom block module as illustrated below:

1. Add new module and select the module type.

 

 

 

 

 

 

2. Select the custom block Body Before End in the Block drop-down:

 

 

 

 

 

Hope this will help others facing same kind of issue.

Today I encountered a sudden problem with administrator login of Joomla 1.7 in Ubuntu 12.04 LTS. The error messages was something like this:

Login: 500 - An error has occurred!

The files were downloaded from LIVE site and tried to run in my laptop. In any case there was no lock.

After Googling sometime I found that it is because of something problems with permission settings for the Joomla folders. Actually in my case one of the required folders/directories “cache” was missed to be downloaded. So what I did to fix the error is:

1. Created the cache folder myself and gave 777 permissions.
2. Gave 777 permissions to following folders:
– tmp
– logs
– cache
– administrator/cache
3. Set all the files 644 permission and 755 for all rest of the folders (except images).

Though sometimes the error message could be due to something else too but in my case it worked like a charm. So I thought that I should share at least someone might be facing the same problem can get some information to fix.

Thanks :-)

Today I was struggling with an issue in Magento. There was a frequent Fatal error message as follows while creating/printing Invoice from Magento back end.

Fatal error: Declaration of Zend_Pdf_FileParserDataSource_File::__construct() must be compatible with Zend_Pdf_FileParserDataSource::__construct() in /web/procuriosqa/x/mikasei/lib/Zend/Pdf/FileParserDataSource/File.php on line 41

I was almost sure this is all about the problem with Zend Framework. I tried to look in the Google if anyone has posted a solution though the solution must be provided by the Zend Framework itself. Then I came to know that there is problem with the implementation of stricter inheritence rule in the framework as described in:

http://framework.zend.com/issues/browse/ZF-12093

http://zend-framework-community.634137.n4.nabble.com/PHP-5-4-0RC1-ZFv1-td4094438.html

And it is all about the PHP bug as reported as here:

https://bugs.php.net/bug.php?id=55375

So the solution would be either one of these:
- Comment out the constructor and destructor methods in the specified class
- Or provide the path of the file explicitly.

For me it was quite difficult to find the exact path of fonts in this case, so I opted for the first solution as suggested here as well:

https://github.com/zendframework/zf2/commit/ad43d3128d61ec67071872d4e4484ea2be1d4d8e

Until Zend Framework team fixed the issue and Magento puts this in the core Magento we don’t have other options as well I think.

When I commented two lines of codes used to define constructor and destructor methods in the file lib/Zend/Pdf/FileParserDataSource.php file which looks like:

abstract class Zend_Pdf_FileParserDataSource
{
    //abstract public function __construct();

    //abstract public function __destruct();
................................................

Now it worked fine.

Hope this will help others too!

Thanks and regards !

Raju

I assume that apache, PHP is running quite fine. But the sending emails from local machine is not working. You need to installl the sendmail and set the path in php.ini. To install follow the below simple steps:

1. Open the terminal and run the following command to install send mail and php mail.

sudo apt-get install sendmail php-mail postfix

2. Uncomment and change the sendmail_path in your file /etc/php5/apache2/php.ini. The line should now look like this:

sendmail_path = /usr/sbin/sendmail -i -t

Somethings without restarting the Apache it might not work so simply restart the apache server once:

$ /etc/init.d/apache2 restart

Now try to run the following PHP mail function:

if(mail("test@test.com", "This some subject", "This is some message body"))
	echo "Sent";
else
	echo "Not sent";

If the mail is sent successfully quickly then fine. But sometimes it does not send the email quickly. It takes sometime i.e. 2 minutes in my case. I googled a lot but could not find a quite proper solution. When I saw the mail log and came to know somehow that it is because not resolving the hostname. I checked my hostname “rajug” in /etc/hosts file which was missing.

1. To check the hostname of your system, run the following command if you don’t know the hostname.

$ cat /etc/hostname # rajug in my case.

2. Make sure something like following line is at your top of the /etc/hosts file.
127.0.0.1 localhost.localdomain localhost
To check it open the file in editor (I use gedit):

$ gedit /etc/hosts

And added the line at top. Actually localhost was there but my hostname “rajug” was not there. So I just added it.

3. Thirdly, edit the sendmail configuration file (/etc/mail/sendmail.cf in Ubuntu) and Uncomment the line:

O HostsFile=/etc/hosts

4. Now restart the sendmail and apache once.

$ /etc/init.d/sendmail restart
$ /etc/init.d/apache2 restart

Now try the above PHP script to send the email, it will send quite faster (2/3 seconds in my case).

Hope this will help others having the same problem !

:-)

We, who normally play/make a use of jQuery, must have used these two functions quite frequently. But have we thought about the performance issues before using jQuery’s functions.

I was needing to append some HTML (LIs) inside an UL and was thinking to use .append() first and I suddenly thought of .html(). And I tried to research in the google and read about both the functions in jQuery’s documentation page. Also found some resources in other discussions forums as well and following were the findings. I thought if I shared it others will get some insight before using.

Whenever we give a string of HTML to any of jQuery’s methods a temporary element is created. Created element’s innerHTML is set to the string of given HTML. Then jQuery will transfer each of the produced nodes (that is newly created element’s childNodes) over to a newly created document fragment, which it will then cache for next time. It will then return the fragment’s childNodes as a fresh DOM collection.

Note that it’s actually a lot more complicated than that, as jQuery does a bunch of cross-browser checks and various other optimisations. E.g. if you pass just

to jQuery(), jQuery will take a shortcut and simply do document.createElement(‘div’). innerHTML is generally the faster approach, although don’t let that govern what you do all the time. jQuery’s approach isn’t quite as simple as element.innerHTML = … — as I mentioned, there are a bunch of checks and optimisations occurring.

The correct technique depends heavily on the situation. If you want to create a large number of identical elements, then the last thing you want to do is create a massive loop, creating a new jQuery object on every iteration. E.g. the quickest way to create 100 divs with jQuery:

jQuery(Array(101).join('
'));

There are also issues of readability and maintenance to take into account.

This:

$('
' + content + '
');

… is a lot harder to maintain than this:

$('
', { id: ID, className: 'foobar', html: content });

So sometimes one replaces the HTML without creating another jQuery object first. The second creates an additional jQuery wrapper for the second DIV, then appends it to the first. See some examples here:

One jQuery Wrapper (per example):

$("#myDiv").html('
');
$("#myDiv").append('
');

Two jQuery Wrappers (per example):

var mySecondDiv=$('
'); $('#myDiv').html(mySecondDiv);
var mySecondDiv=$('
'); $('#myDiv').append(mySecondDiv);

You have a few different use cases going on. If you want to replace the content, .html is a great call since its the equivalent of innerHTML = “…”. However, if you just want to append content, the extra $() wrapper set is unneeded.

Only use two wrappers if you need to manipulate the added div later on. Even in that case, you still might only need to use one:

var mySecondDiv = $("
").appendTo("#myDiv"); // other code here mySecondDiv.hide();

Source: stackoverflow questions page. I don’t remember now the question page now as this was just copied couple of days ago in a text file and now I am just compiling it for others.

Hope this will help others to understand somethings about jQuery.

:-)

phpmyadmin has an error and stops working when PHP version is upgraded to 5.4.

Solution:

1. Either you upgraded the lastest phpmyadmin 3.4.10.x.
2. They provide the patch file. If you cannot find it then simply change the code in the given file as follows:
Old:
$this->getBacktrace()

New:
serialize($this->getBacktrace())

Hope this helps someone having the problem.

Cheers !

Installing AMP (Apache, MySQL and PHP) have become quite easier with single wizard based installations available as a packet these days. Like using XAMPP, WAMP you can just install them and use. But with these setups, you will have (or will not have) less knowledge about configuring them each in your own way because they will present some user interface where you can directly do configurations by one click. You will not know what exactly required for changing something in Apache, PHP or MySQL. So to have knowledge on configurations on them according to your requirement, you have to install each applications individually. I always recommend to do that and configure them for your purpose.

The installation and configurations of PHP, Apache and MySQL in Windows has also become quite easier these days because they provide some default configurations. As PHP, after its latest releases i.e.5.4, does not provide the downloads of VC6 version (the PHP compiled with Visual C++ 2006 compiler) these days because it is believed that the performance of the PHP compiled with VC9 (compiled with Visual C++ 2008 or later) has improved quite a lot than the compiled with VC6. So to work with the latest VC9 version of PHP, you must have installed PHP with VC9 compiled Apache as well or you use IIS as web server. VC9 compiled Apache is provided by Apache Lounge (apachelounge.com) not the original Apache (apache.org). Since I haven’t worked yet with IIS and always work with Apache in anyway, I don’t have knowledge about the IIS & PHP. Here I am going to explain few steps on how to install PHP 5.4 and Apache 2.4 in Windows.

Requirement

To run the applications compiled with VC8 or VC10, it is required to install the respective (or latest one is always better) Visual C++ redistributable packages. You can download the package from Microsoft’s official site for free.

Note: If you have any Visual Studio installed in your PC then you don’t have to install them separately.

Where to install?

Since I have not used any installers for both PHP and Apache, I will be downloading the pre compiled zipped packages and install them in my D drive. The folder structure will look like below:

  • d:/etc/apache                                   – Apache installation
  • d:/etc/php                                          – PHP installation
  • d:/etc/mysql                                      – MySQL installation
  • d:/etc/mysql/databases               – MySQL data folder
  • d:/etc/www                                       – document root folder

Note: You can change the drive and path for the installations in your own way.

Download

  1. Download the latest Apache 2.4.1 (as of writing this) from http://www.apachelounge.com/download/ (direct link for the current version – http://www.apachelounge.com/download/win32/bins/httpd-2.4.1-win32.zip) and unzip it in d:/etc/apache
  2. Download latest version 5.4 from http://windows.php.net/download and unzip it in d:/etc/php. While downloading PHP, choose the Thread Safe version for windows.
  3. Download the PHP and Apache connector DLL file from http://www.apachelounge.com/download/ (direct link: http://www.apachelounge.com/download/win32/mods-2.4/php5apache2_4.dll-php-5.4-win32.zip) and extract the file php5apache2_4.dll and copy it to d:/etc/php.

Configurations

Though the configurations may vary from individual’s requirement but here I will be discussing for some basic configurations in PHP and Apache.

Apache

  1. Open the file d:/etc/apache/conf/httpd.conf in any text editor (I use my lovely Notepad++) then find and make the following changes/configurations as per your installation path.
  2. Set the server root
    ServerRoot "D:/etc/apache"
  3. Enable required Apache modules. I just uncomment one more for mod_rewrite module.
  4. Add the following lines somewhere (I did just below the module enabling)
    LoadModule php5_module "d:/etc/php/php5apache2_4.dll"
    AddHandler application/x-httpd-php .php
    PHPIniDir "d:/etc/php"
  5. Change server admin email address
    ServerAdmin info@yoursite.com
  6. Change the document root:
    DocumentRoot "d:/etc/www"
    <Directory "d:/etc/www">
  7. If you want to allow .htaccess to be used under document root do the following under <Directory “d:/etc/www”>
    AllowOverride All
  8. Find the follwoing and replace the path:
    ScriptAlias /cgi-bin/ "d:/etc/apache/cgi-bin/"
    <Directory "d:/etc/apache/cgi-bin">
  9. Add index.php in directory index
    DirectoryIndex index.html index.php

PHP

  1. Rename php.ini-development to php.ini
  2. Find extension directory setting and set the path as per your installation.
    extension_dir = "d:\etc\php\ext"
  3. Uncomment (remove the simicolon ; from the beginning of the line) the extensions that you want to enable them. i.e.
    extension=php_curl.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll
    extension=php_pdo_mysql.dll
    extension=php_soap.dll
  4. If you want to test email sending from the PHP in local system, then you need to set the SMTP. i.e.
    SMTP = smtp.yoursite.com
    smtp_port = 25
    sendmail_from = youremail@sender.com

Rest of the changes/configurations are totally depends on requirement project wise.

Set Environment Variables for PHP (Windows 7)

To be available PHP globally in Windows, the path of the PHP has to be set.

  1. Right click on Computer and click Properties
  2. Click on Advanced system settings on the left side (top).
  3. Click on the Environment variables
  4. Under System variables, double click the Path variable name and add ;d:\etc\php without double quotes at the end where semicolon (;) is the separator.
  5. Click OK to save. Sometimes you may need to restart the computer this to take it into effect.

Install Apache as Service

Since we have just copied the files in a folder, the Apache is not yet not a windows service. To install it as a service follow the steps.

  1. Run the command line (cmd.exe) As Administrator. Browse the folder c:\Windows\System32\ and right click on cmd.exe and select Run as Administrator.
  2. Change directory to d:\etc\apache\binin the command line
    cd d:\etc\apache\bin
  3. Run the command to install it
    httpd -k install (or sometimes httpd.exe -k install if that does not work)

Now restart the computer and test both PHP and Apache. To test both together create a PHP file phpinfo.php in d:\etc\www. Now browse in the browser as http://localhost/phpinfo.php.

If you can see the PHP information then now you are done !

About Me

I am an Opensource Developer. Currently I am working in a company as a Solution Architect. I have around 7 years of Web development experience in Advanced and Core PHP Programming and MySQL and PgSQL database as back end. It has been long time that I have nott been involved with RoR, Perl and ASP, Visual Basic but I had also worked with them. Specialties: PHP, Zend, YII, CodeIgniter, Joomla, Magento, JavaScript, MySQL, PgSQL, HTML, CSS, RoR, Perl, ASP!

Switch to our mobile site