Thursday, April 28, 2011

Install libphp-phpmailer in Ubuntu

The only PHP function that supports this is the mail() function. However, it does not expose any of the popular features that many email clients use nowadays like HTML-based emails and attachments. There are two proprietary development tools out there that have all the functionality built into easy to use classes: AspEmail(tm) and AspMail. Both of these programs are COM components only available on Windows. PhpMailer implements the same methods (object calls) that the Windows-based components do. Class Features: – Send emails with multiple TOs, CCs, BCCs and REPLY-TOs – Redundant SMTP servers – Multipart/alternative emails for mail clients that do not read HTML email – Support for 8bit, base64, binary, and quoted-printable encoding – Uses the same methods as the very popular AspEmail active server (COM) component – SMTP authentication – Native language support – Word wrapTo install this package in Ubuntu,

$ sudo apt-get install libphp-phpmailer

Monday, April 25, 2011

Function to get client IP address

function get_ip_address() {
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
if (array_key_exists($key, $_SERVER) === true) {
foreach (explode(',', $_SERVER[$key]) as $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
return $ip;
}
}
}
}
}

or

function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}

mysql data directory

Mysql data directory is important part where all the mysql databases storage location.By default MySQL data default directory located in /var/lib/mysql.If you are running out of space in /var partition you need to move this to some other location.

Path to the default data directory of mysql in Ubuntu


/var/lib/mysql

Friday, April 22, 2011

htaccess file to run the two compression scripts and cache images for wordpress

Add entries to your Website .htaccess file to run the two compression scripts and cache images

Add the following to the end of the .htaccess file (usually at the root of your Website). If a file named .htaccess doesn’t exist then create a file named .htaccess in a text editor, add the text below and then transfer to the root of your Site.

# BEGIN Compression and Caching Script per http://wordpresspartner.com

# This calls the ‘compress-css.php’ and ‘compress-js.php’ files


RewriteEngine on
RewriteRule ^(.*\.(css))$ compress-css.php?file=$1
RewriteRule ^(.*\.(js))$ compress-js.php?file=$1


# This enables caching


Header set Cache-Control “max-age=2592000, public”


Header set Cache-Control “max-age=216000, public, must-revalidate”


Header set Cache-Control “max-age=1, private, must-revalidate”



# End Compression Script

The method as described above has been tested with WordPress Sites hosted by Godaddy

Create a PHP file to compress JavaScript for wordpress

?

ob_start(“ob_gzhandler”);

header(“content-type: text/javascript; charset: UTF-8″);

header (“expires: ” . gmdate (“D, d M Y H:i:s”, time() + 302400) . ” GMT”);

header(“Cache-Control: max-age=302400, private, must-revalidate”, true);

echo “/*\n”;

echo file_get_contents($_GET['file']);

?
save the file created in a file for future use

Create a PHP file to compress CSS for Wordpress

Here is the code for that
?
ob_start("ob_gzhandler");
header("content-type: text/css; charset: UTF-8");
header ("expires: " . gmdate ("D, d M Y H:i:s", time() + 302400) . " GMT");
header("Cache-Control: max-age=302400, public, must-revalidate", true);
echo "/*\n";
echo "*/\n";
echo file_get_contents('filename.css');
?

Monday, April 18, 2011

.htaccess file – Increase execution time, session expiry time and file upload size limit



php_value post_max_size 5M

php_value upload_max_filesize 5M

php_value memory_limit 300M

php_value max_execution_time 259200

php_value max_input_time 259200

php_value session.gc_maxlifetime 1200




php_value memory_limit 300M - Set higher default php_value memory_limit in .htaccessupload_max_filesize 5M - it increases default upload limit. The default upload limit is 2MB. the above htaccess increase increases file limit 2mb to 5 mbphp_value max_execution_time: Set the number of seconds a script is allowed to run. If this is reached,the script returns a fatal error. The default limit is 30 seconds or, if itexists, the max_execution_time value defined in the configuration file. Ifseconds is set to zero, no time limit is imposed.php_value session.gc_maxlifetime: The session.gc_maxlifetime only sets the age of the session files that will be deleted whengarbage collection runs.If you have a busy web site with a lot of sessions being created, garbage collection willrun based on session.gc_probability/session.gc_divisor. Despite this being called"probability" I tested this and it is strictly a count. Using the defaultgc_probability/gc_divisor of 1/100, this means that garbage collection will run every 100new sessions (Edit: Actually this occurs within the session_start() coding and would countre-started sessions as well) and delete any existing session files that are older than thesession.gc_maxlifetime. There is no file locking on the session files, so active sessionfiles will be deleted and things like users getting logged out will occur.If this is on shared hosting and the session files are all kept in the default location andsomeone else is using a smaller session.gc_maxlifetime or a more frequentgc_probability/gc_divisor, then any of the session files will get deleted based on thelowest value of gc_maxlifetime and the most frequent gc_probability/gc_divisor.You need to increase session.gc_maxlifetime or make session.gc_divisor larger and if this ison shared hosting, set session.save_path to be a location within your web space.

Tuesday, April 12, 2011

How can i get back the archived emails in gmail

Archiving lets you tidy up your inbox by moving messages from your inbox into your All Mail label, so you don't have to delete anything. Any message you've archived can be found in All Mail, in any labels you've applied to it, and in Gmail search results. When someone responds to a message you've archived, the conversation containing that message will reappear in your inbox.

To archive messages:

1. In your inbox, select a message by checking the box next to the sender's name.
2. Click Archive. (If you have a message open, you can also archive it by clicking the Archive button.

To move an archived message back to your inbox, follow these steps:

1. Click All Mail. (If you don't see All Mail along the left side of your Gmail page, click the More drop-down menu at the bottom of your labels list.
2. Check the box next to the sender's name.
3. Click the Move to Inbox button.

Thursday, April 7, 2011

How to set screen resolution in Ubuntu

In ubuntu 9.1

Goto System->Preferences->Display

IN the screen displayed you can change the resolution.


In ubuntu 10

Goto System->Preferences->Monitor

IN the screen displayed you can change the resolution.

How do I set system time and date from terminal ubuntu ?

you can do that by typing in the following format:

sudo date mmddHHMMYYyy

so
sudo date 060702031980
Sat Jun 7 02:03:00 IST 1980

or

Set hwclock manually:
# hwclock --set --date="9/22/96 16:45:05"

Yes for some reason debian and ubuntu are very date sensitive.