Tag Archives: PHP

jQuery & Javascript – Capture the Browser or Tab Closed Event

I was working on a WordPress project which i need to clear the PHP session when the browser or browser tab is closed. Although Javascript provides the window.onbeforeunload event but it will be triggered even whenever you leave the website. Finally i got a simple solution from Daniel Melo in StackOverflow. The following code required jQuery and i have included the Google one in the HTML.

In your web root, create the js/check_browser_close.js. Continue reading jQuery & Javascript – Capture the Browser or Tab Closed Event

Ajax – Simple Ajax GET Request

This is another example of implementing simple Ajax GET request. Please refer to Ajax – Simple Ajax POST Request for a POST request. Actually, both of them are quite similar and it is good to try both to get more familiar with the generic Ajax requests.

Let’s start our example now. Continue reading Ajax – Simple Ajax GET Request

WordPress – Enable PHP Session

Add the following code under the top PHP opening tag of wp-config.php.

<?php
  if (!session_id()) {
    session_start();
  }
...

We can now make use of the $_SESSION[] in WordPress. The reason of putting the session_start() in wp-config.php is because this configuration file will not be overwritten during a WordPress update.

Thanks Frank Verhoeven.

Done =)

Reference: Frank Verhoeven – Using Sessions in WordPress

Updated @ 2012-08-02: Please note that their maybe security issue of using the PHP session. For more information, please refer to the following link.
PHP $_SESSION variables

Drupal – Fix Ubercart Error Messages

If you get a bunch of error messages after installing Ubercart as follow

  • # Notice: Undefined index: #element_validate in summarize_form() (line 27 of /var/www/pressflow-6.20/sites/all/modules/ubercart/uc_store/includes/summaries.inc).
  • # Notice: Undefined index: #type in summarize_element() (line 84 of /var/www/pressflow-6.20/sites/all/modules/ubercart/uc_store/includes/summaries.inc).
  • # Notice: Undefined index: #type in summarize_element() (line 124 of /var/www/pressflow-6.20/sites/all/modules/ubercart/uc_store/includes/summaries.inc).

No worry, these messages could be removed after modifying the error reporting setting in the php.ini. Continue reading Drupal – Fix Ubercart Error Messages

Configure Postfix/Sendmail for PHP mail() in Ubuntu

Actually configure Postfix or Sendmail for PHP mail() is the same. Both of them run the /usr/sbin/sendmail binary. It is quite confusing if we just look at the name of the binary but this is what Postfix did.

For more information, take a look at the Postfix Manual – sendmail.

For the PHP setting, open the /etc/php5/apache2/php.ini and configure the sendmail_path. Continue reading Configure Postfix/Sendmail for PHP mail() in Ubuntu

Drupal – Enable Custom PHP Code Condition for Rules

Last time i have shown you the basic usage of the Rules module.
Drupal – Build Simple Workflow with Rules

Whenever a rule is fired, you can add some conditions to validate if the actions should be run. And you can even setup a PHP code condition for rule. But this feature required the PHP Filter in the Drupal Core modules.
Continue reading Drupal – Enable Custom PHP Code Condition for Rules

Drupal – Customize Fonts in Drupal

If you find the fonts of your Drupal site quite boring. The @font-your-face module could make the text of your Drupal site more fun. Before proceeding, it would be great if your PHP is already enabled with the zip extension. but no worry if you doesn’t have the zip extension. We can still complete it without any problem.

Download and enable module with those free fonts. Continue reading Drupal – Customize Fonts in Drupal