Absolutely Tech

[Solved] Disqus causing admin panel issues in wordpress

Disqus comment system was causing javascript errors, which in chrome console looked something like this:

Uncaught Syntax error, unrecognized expression: [href=edit-comments.php?page=disqus]

It caused unmovable widgets, screen-options didn’t open and other related javascript issues in admin panel.

After some researching it turns out, there’s a simple fix.

In /wp-content/plugins/disqus-comment-system/disqus.php, find:

href=edit-comments.php?page=disqus

and replace it with:

href=”edit-comments.php?page=disqus”

Cheers

[HowTo] Stop phpmyadmin from asking username, password in localhost

Yesterday, I showed you how you can keep local installation of phpmyadmin from logging you out every few minutes. I took one more step and edited configuration to not ask me username, password at all. Now phpmyadmin never asks me for mysql username and password.

Keep in mind if you follow this tutorial anyone would be able to access your database using phpmyadmin unless you deny access via apache configuration. Don’t do this on production servers.

Steps to follow:

  • Run: gksudo gedit /etc/phpmyadmin/config.inc.php
  • Find:
    $cfg['Servers'][$i]['auth_type'] = 'cookie';

    And change it to:

    $cfg['Servers'][$i]['auth_type'] = 'config';
  • Just below this line, add:
    $cfg['Servers'][$i]['user'] = '';
    $cfg['Servers'][$i]['password'] = '';

    Replace and with mysql username and password.

  • Save the file.
  • Changes will be applied immediately, no need to restart apache.

Now, you’ll never have to enter username and password in phpmyadmin.

Cheers!

[HowTo] Extend phpmyadmin session expiration time

Recently, I got frustrated being logged out every few minutes (24 minutes, to be precise) from phpmyadmin on my localhost. I make some db changes, write some code and when I get back to phpmyadmin, I would see my session had expired. To fix this, I changed the configuration so that my session would expire only after 24 hours of inactivity.

Steps to follow:

  • Copy the following code at the end of /etc/phpmyadmin/config.inc.php:
    $cfg['LoginCookieValidity'] = 60*60*24;
    ini_set('session.gc_maxlifetime', $cfg['LoginCookieValidity']);

This will let your session expire only after 60*60*24 seconds, that is one day.

Cheers!

[HowTo] Remove admin bar from wordpress 3.1

The new admin bar in wordpress 3.1 is one good feature to have but sometimes its unwanted. For example you might already have some other kind of top bar with which admin bar may interfere. You can remove the admin bar by putting the following code in /wp-content/YOURTHEME/functions.php:

if(function_exists('show_admin_bar')){
	show_admin_bar(false);
}

[SOLVED] ‘Error at offset’ error in unserialize()

I came across this weird error in unserialize() where it refused to unserialize the serialized data. After hours of trying different things to solve it, finally converting the encoding worked.

The solution to the problem is to use the following function instead of unserialize():

function safe_unserialize($str){
       return unserialize( trim( mb_convert_encoding( $str,'auto','UTF-8' ) ) );
}

Cheers!

[HOWTO] Fix Twitter clients (or PHP scripts) which use basic authentication.

As you probably know, Twitter completely ditched basic authentication method on August 31st, 2010. It now supports only OAuth method of authentication which complicates the coding process multiple folds. Scripts which were previously 20 lines long now span several files.

While there are numerous advantage of Oauth like client doesn’t need to know your password, increased security etc, lots of twitter clients which used basic authentication stopped working right away after Aug 31st.

However, there had to be someone to the rescue. This time it’s http://www.supertweet.net/. They act like a proxy between twitter and your app, converting all basic authentication requests to oauth requests. So practically, twitter will be getting oath requests and your app would still be making basic authentication requests. This would help the twitter clients or php scripts to still use the same code and function just like before.

Documentation:
http://www.supertweet.net/about/documentation
The process is pretty simple and you should get through everything without a hitch.

You just have to change the API url from http://api.twitter.com/ from the application settings or PHP code to http://api.supertweet.net/.

If you still have problems, post it in comments.

Cheers!

[HowTo] Add expires headers to cache static files using htaccess

Caching is one of the most important things to keep in mind when you are developing a website which is expected to get large amount of visitors. Most web developers neglect caching, some even don’t know correct ways to implement it.

In this tutorial, I’ll show you how to enable browser cache of static files simply using htaccess file. Basically server adds the Expires header to file-type you specify. Expires header will make sure the browser stores the file locally and use the same file until the time mentioned in expires header has passed.

Before we move ahead, please make sure apache’s mod_expires is loaded. You can check it using phpinfo() under ‘Loaded Modules’ section. If you don’t find it there, you can see this tutorial to enable mod_expires.

Copy the following code and paste it into .htaccess file in your website’s root directory.

# Turn on the Expires engine
ExpiresActive On
 
# Expires after a month client accesses the file
ExpiresByType image/jpeg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/plain A2592000
 
# Good for one week
ExpiresByType application/x-javascript M604800
ExpiresByType text/css M604800
ExpiresByType text/html M604800

Explanation:

ExpiresActive On turns on the expires engine. ExpiresByType image/jpeg tells server to check if MIME-type of file is image/jpeg. If yes, set the expires header.
Read the rest of this entry »

[HowTo] Enable or disable modules in Apache

You can enable or disable any apache module using a2enmod and a2dismod. You don’t need to edit the conf file for that unless you are having some problem with this method. The syntax of these commands is really simple:
To enable a module:

sudo a2enmod module_name

To disable a module:

sudo a2dismod module_name

Read the rest of this entry »

[HowTo] Check your php and server information using phpinfo()

We can check the php configuration, apache’s loaded modules and all other kinds of PHP configuration using a simple function called phpinfo(). Create a file called infophp.php in your web’s root directory and put the following code in it:

<?
phpinfo();
?>

This would output all the php configuration info and apache information. You can pass on an argument to phpinfo() to limit what information is displayed. You can checkout the phpinfo documentation here.

PS: This is a beginner tutorial for absolute beginners.

[HOWTO] Send emails(using mail function) from localhost in PHP through msmtp (using gmail account) on Linux

There’ve been lots of times when I wanted to use the mail() function on my local server. I am sure lots of you would’ve been wanting it too but most of you would’ve settled for PHPMailer or just used a web host to test the code instead. I myself had been doing the same until recently when I finally decided to do some research and get it to work.

Here are the steps in short for the geeks who like to do things on their own:
All I did was used smtp client called msmtp, configured it to work with my gmail account and configured PHP to use msmtp to send emails.

This tutorial is only applicable for linux users. I’ll write another article for windows users soon when I get my hands on a windows box.
All the commands used in the instructions are for Ubuntu, however you may use corresponding commands for your distro (for eg; you can use yum install instead of apt-get install on fedora, redhat, centos.

Step by step instructions:

Read the rest of this entry »