Drupal 6

If you want to resolve this error there can be 2 ways:

1) Empty(Truncate) all the cache tables from your database. For example empty all tables suffix by "cache_" like cache, cache_block, cache_content, cache_filter, cache_form, cache_menu, cache_page, cache_update, cache_views.

2) Your MySQL credentials are not right. Check your settings.php see if your MySQL credentials are right. Either your database username, passport or host is wrong.

Settings file protection by password encryption

Settings.php was criticized for storing the plain text MySQL username and password. This procedure will let us remove the username and password from the settings.php and let us put that credentials outside of the website directory and store into another folder which can be taken care by security team or server managing people.

To do this, include a line at the top of settings.php file:

require_once '../secure_mysite/secure_credentials.php';

This line specify that include a script called “secure_credentials.php” and if it’s not found, stop the script from further running. For now, we have created a secure folder called “dbpw” which we have stored outside of website directory. We stored our php script into this folder and call that script using above line inside settings.php.
This secure_credentials.php contain two function i.e. one for encryption and one for decryption.


function encrypt_credentials($username, $password, $encrypted_key = NULL, $iv = NULL) {
  $method = "AES-256-CBC";
  $password_file = "/www/htdocs/secure_mysite/pass.txt";
  $key_file = "/www/htdocs/secure_mysite/key.txt";
  $wasItSecure = true;
  $ivlen = openssl_cipher_iv_length($method);
  $iv = openssl_random_pseudo_bytes($ivlen, $wasItSecure);

  if (!file_exists($key_file)) {
  	if(!$fh = fopen($key_file, "w")) { die("

Could Not Open Key File"); } $encrypted_key = openssl_random_pseudo_bytes(32); $result = fwrite($fh, $encrypted_key); fclose($fh); } $encrypted_data = openssl_encrypt($password, $method, $encrypted_key, 0, $iv); //create a file handler by opening the file if(!$fh = fopen($password_file, "w")) { die("

Could Not Open Password File"); } $txt = $username . ":" . $encrypted_data . ":" . $iv; $result = fwrite($fh, $txt); if($result) echo "Username and Password successfully encrypted and stored\n"; fclose($fh); } function decrypt_credentials($param) { $password_file = "/www/htdocs/secure_mysite/pass.txt"; $key_file = "/www/htdocs/secure_mysite/key.txt"; $method = "AES-256-CBC"; $filecontents = file_get_contents($key_file); $all_words = preg_split('/[\s]+/', $filecontents, -1, PREG_SPLIT_NO_EMPTY); if(!$fh = fopen($password_file, "r")) { die("

Could Not Open Password File"); } while(!feof($fh)) { $line = fgets($fh, 4096); $from_file = explode(":", $line); } $decrypted_pass = openssl_decrypt($from_file[1], $method, $all_words[0], 0, $from_file[2]); fclose($fh); return ($param == 'username') ? $from_file[0] : $decrypted_pass; }

Encryption Function:

function encrypt_credentials($username, $password, $rand_pass = NULL, $iv = NULL) {}

This function takes 4 parameters in which 2 are optional, but username and password is required. This function used AES-256-CBC encryption method to encrypt the password. To use the encryption properly I have used:

string openssl_encrypt ( string $data , string $method , string $password [, int $options = 0 [,string $iv = "" ]] )

For making this script more automatic and independent I have generated 3rd argument $encrypted_key in above function by using an inbuilt function openssl_random_pseudo_bytes(). This key will be stored in a separate key file called “key.txt”. The key will be generated only once when the program runs first time. If you want to generate a new or different key you have to delete key.txt file. The openssl_encrypt() function require one more parameter which is “iv” (initialization vector) as the 5h parameter. The “iv” is generated automatically in this script by PHP inbuilt function openssl_random_pseudo_bytes(). Then all these parameters passed into openssl_encrypt() function to generate the encrypted data. The generated data will be stored inside “pass.txt” file. This text file contain 3 parameters as well which are separated by “:” parameter.
Username: Encrypted Data: IV

To run the above function we need to run this command by CD into the folder and then run the command from the command line:

 php -r 'require "secure_credentials.php";encrypt_credentials("superman", "makeitsecure!#2");' 

Where superman is example of username and makeitsecure!#2 is the password.

You will only need to run this command with username and password. With this command it will call the encrypt_credentials() function inside the secure_credentials.php file and store the results in pass.txt file. File pass.txt will look something like this:

 superman:cmWK+ymPjL7vB5v4+FM39A==:°ß™™ÊÏ s߈ÜÄVë 

When the settings file will run it will call the decrypt function.
The two statements inside the settings file will call the decrypt function in the secure_credentials.php file.

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'yourdb',
      'username' => decrypt_credentials('username'), //Note this statement
      'password' => decrypt_credentials('password'), //Note this statement
      'host' => 'localhost',
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',

When this function is called, it looks for the pass.txt, opens it and decrypt the password and send the password in the decrypted format to the Drupal back again.
By above process we are not storing the plain password anywhere and the password will be only known by the Person who will run the command line function. If he forgots the password, this command line function needs to be run once again.

You have to open authcache.helpers.inc and add if (headers_sent()) return; to the top of _authcache_shutdown_save_page().

Please refer to this post https://drupal.org/node/758380

Sometime you want to remove the anchor tags or links from the product links from the shopping cart block. To do this you have to override the uc_cart_block_items() in your

template.php file. Then search for the link and remove that from function. Here is a sample of this (with removed links from that function) :  you have to copy and paste this function into your current theme template file . Then replace the YOURTHEMENAME with your current theme name.

function YOURTHEMENAME_uc_cart_block_items($items) {
  if ($items) {
    $output = '';
    $row_class = 'odd';

    $context = array(
      'revision' => 'themed',
      'type' => 'price',
    foreach ($items as $item) {
      $context['subject'] = array(
        'cart_item' => $item,
        'node' => node_load($item['nid']),
      $output .= ''. $item['qty'] .''
                .''. strip_tags($item['title']) .''
                .''. uc_price($item['price'], $context) .'';

      if ($item['desc']) {
        $output .= ''. $item['desc'] .'';
      $row_class = ($row_class == 'odd') ? 'even' : 'odd';

    $output .= '';
  else {
    $output = '

'. t('There are no products in your shopping cart.') .'

'; } return $output; }
Ubercart Shopping block with no product links

On shared server you dont have an access to "root", so your su command will not work.  Now if you have to add anything or modify the settings in php.ini file, you have to create a local copy of php.ini file for your website on root.

To do this, you have to login into SSH (Secure Shell) by using a program like putty  .

After you login, copy your php.ini file using cp command 

cp /web/etc/php.ini  /var/www/vhosts/sitename/php.ini

You might have different paths, if you dont know where is your php.ini file over the server, you can use the following command to find the file

find . -type f -name 'php.ini' 

Now you can change anything in your php.ini file and save it. You can view the changes by going here admin/reports/status/php in your drupal website.


We enable all the "performance settings" which includes "javascript and css optimization" . Sometimes that javascript or css optimization can conflict on various pages and create various bugs, disturb the design of our page, misplace the elements on the page.

To prevent from this, we can disable the JS or CSS to render on that particular pages. To do this we have to use drupal's global configuration variable . Suppose you want to prevent JS and CSS on blog creation page then  :

 global $conf;

 if((arg(0) == 'node' && arg(1) == 'add' && arg(2) == 'blog')) {
         $conf['preprocess_css'] = FALSE;
         $conf['preprocess_js'] = FALSE;


1. Put your website in offline mode inside your site maintenance mode.

2. Download the latest module from drupal.org.

3. Backup your database and module which you are going to replace, incase something went wrong. 

4. Replace that module with latest module that you have downloaded from drupal.org.

5. Go to your website and run update.php script . For example www.example.com/update.php .

6. Run the update steps and thats it !

In Drupal 6 you can for the FORM API :

// register a new user
$form_state = array();
$form_state['values']['name'] = 'robo-user';
$form_state['values']['mail'] = 'robouser@example.com';
$form_state['values']['pass'] = 'password';
$form_state['values']['op'] = t('Create new account');
drupal_execute('user_register', $form_state);

This is due to that you have recently upgraded your PHP version from 5.2 + to 5.3 + . 

To solve this you either have to re-install the PHP 5.2+ version again like 5.2.9 .


Replace the ereg($mask, $file) with mb_ereg($mask, $file) in file.inc specifically on line 902.

HTML/Drupal Disabled element/attribute :

1. If the disabled attribute is used, then the value do not get passed to the form processor while submitting the form. It means you cannot receive the values of that element to process them.

2. You can not set focus on these elements .

3. You can not navigate these elements with the help of TAB.


HTML/Drupal Readonly element/attribute :

1. If the Readonly attribute is used, then the value get passed to the form processor and you can process the values which are submitted by Readonly element.

2. You can set focus on these elements .

3. You can navigate these elements with the help of TAB.


Subscribe to RSS - Drupal 6