Absolutely Tech

[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);
}

[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] Validate Email-address in PHP using Regular expressions (the correct way)

Here’s a function which thoroughly checks email-address and returns true for a valid email address and returns false for invalid one. I thought it was worth sharing so I posted it on my blog. You will find the source link at the bottom.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email 
address format and the domain exists.
*/
function validEmail($email)
{
   $isValid = true;
   $atIndex = strrpos($email, "@");
   if (is_bool($atIndex) && !$atIndex)
   {
      $isValid = false;
   }
   else
   {
      $domain = substr($email, $atIndex+1);
      $local = substr($email, 0, $atIndex);
      $localLen = strlen($local);
      $domainLen = strlen($domain);
      if ($localLen < 1 || $localLen > 64)
      {
         // local part length exceeded
         $isValid = false;
      }
      else if ($domainLen < 1 || $domainLen > 255)
      {
         // domain part length exceeded
         $isValid = false;
      }
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
      {
         // local part starts or ends with '.'
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $local))
      {
         // local part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
      {
         // character not valid in domain part
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $domain))
      {
         // domain part has two consecutive dots
         $isValid = false;
      }
      else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                 str_replace("\\\\","",$local)))
      {
         // character not valid in local part unless 
         // local part is quoted
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
             str_replace("\\\\","",$local)))
         {
            $isValid = false;
         }
      }
      if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
      {
         // domain not found in DNS
         $isValid = false;
      }
   }
   return $isValid;
}

Usage Example:

if(validEmail($_POST['email']))
echo 'Valid Email';
else
echo 'Invalid Email';

Source/Reference

Cheers!

[HOWTO] Use local phpmyadmin with remote MySQL

My host recently started allowing remote connections to its mysql database. It was a really useful feature – I could not change database settings from my own computer. Since it started allowing remote connections from my IP, I could use any mysql client to connect to it. I fired up terminal and tried to connect using the command:

mysql --host=69.89.31.242 --user=username --password=password

It connected. This was just to test the connection. I wanted to connect my phpmyadmin with this remote host. For that I edited /etc/phpmyadmin/config-db.php file and changed:

$dbserver=”;

to

$dbserver=’69.89.31.242′;

I loaded the url http://localhost/phpmyadmin, entered the database username and password and I got in. I could administer my database from my local phpmyadmin installation.

Cheers!

[SOLVED] Flush(), ob_flush() not working in PHP (Disabling gzip through htaccess)

Flushing the output buffer doesn’t works in PHP sometimes no matter what you do. I had this code which would never work on my server but would perfectly fine on localhost. This was the code.

<?php
include('common.php');
ini_set('output_buffering','on');
ini_set('zlib.output_compression', 0);
//ini_set('implicit_flush',1);
ob_implicit_flush();
for($i=0;$i<10;$i++) {
      echo $i;
      echo str_repeat(" ", 500);
      ob_flush();
      flush();
      sleep(1);
}
?>

Read the rest of this entry »

Missing alphabet check (is_alpha) in PHP

Well, you might have seen a huge number of variable checks ranging from is_file(), is_array() to is_numeric() and is_int(). While developing a script today I wanted to check for alphabets. I directly used is_alpha() but to my surprise it wasn’t defined.

Read the rest of this entry »

Using CodeIgniter’s Email library separately

I’ve developed my own libraries for rapid development of PHP applications. Email library is one area which I didn’t feel like developing a library for. Just then, I remembered how simple and robust CodeIgniter’s Email class was. I decided to try it on my own script. It was not at all difficult to get it working. It just commented out few lines of codes and voila! I was able to send my first email.

Those who are in need of a email library could use this simple library separately. I’ll guide you through the whole process step by step.

First thing you need to do is copy the Email.php from system/libraries folder and place it inside your script. Then use your favorite IDE to edit these lines:
Read the rest of this entry »

Installing a web server package for PHP development

So, you thought you would make a web application but didn’t know where to start?
This is the place to start. You need a web server installed on your computer before you start any kind of web programming be it PHP, ASP .Net, ColdFusion, JSP.

For developing in PHP, you would have to install an Apache HTTP server, php interpreter, MySQL server. Installing all of them would be a real headache and so would be configuring them to work with each other. To simply this we have WAMPs(Windows Apache, MySQL, PHP).

One such WAMP distribution is XAMPP which is cross platform and has many features inbuilt like filezilla ftp server, a mercury mailing server etc.

To install XAMPP first download the installer file for your OS from the following link:
http://www.apachefriends.org/en/xampp.html

Read the rest of this entry »