web of unni

About | GuestBook | Add WebOfUnni to Google ToolBar

Download Day

May 12, 2008

Changing time zone in php info page

Filed under: php, time zone — unni @ 5:39 pm

The “precedence order” of the time zone in php is like below :
=============================================================
* The timezone set using the date_default_timezone_set() function (if any)
* The TZ environment variable (if non empty)
* The date.timezone ini option (if set)
* “magical” guess (if the operating system supports it)
* If none of the above options succeeds, return UTC
================================================================

So if you need a custom time zone in the php info page which is returned by the phpinfo function then follow the below steps :

1. Find the php.ini file

#php -i | grep php.ini

2. add the below line to it

date.timezone=Asia/Calcutta

You can get more supported time zone from

компютриhttp://in.php.net/manual/en/timezones.php

3. Save the file and restart webserver, in most cases Apache

#service httpd restart

Thats All :-)

November 27, 2007

Parsing html as php

Filed under: apache, iis, php, windows — unni @ 9:50 pm

Some times we need to parse html files as php. You do the following for the same.

1. Apache
in the website document root create a directory called .htaccess and add the following to that file.

=================================
AddType application/x-httpd-php .inc .php .phtml .html
AddType application/x-httpd-php-source .phps
==================================

Now yout html files will be parsed as php

2. Windows IIS

* Go to IIS manager ( Start >> Programs >> Administrative tools >> IIS manger )
* Right click on the website and get the properties. In the Home directory tab click on application configuration.
* Get the executable path corresponding to php extension.
* Click on add new application extension
* Enter the executable path as that you got from php extension. Enter the extension as .html
* Click Ok.
Now your windows machine will parse your html files as php

September 27, 2007

Overriding default Return-path in mail header using php mail

Filed under: mail, php — unni @ 2:15 pm

When sending mails using php script default return path in mail header will be something like nobody@host.com. By adding some additional parameter in php mail function we can replace the default return path.

Php mail function has 5 parameters

1. To
2. subject
3. message
4. additional_headers
5. additional_parameters

So when sending mails using php mail function we can add -f myname@myself.com in additional_parameters section to replace the return path with our mail id.

Sample code for replacing return path with wemaster@example.com is given below

<?php
$to = ‘unnikrishnan.a@gmail.com’;
$subject = ‘the subject’;
$message = ‘hello’;
$headers = ‘From: webmaster@example.com’ . “\r\n” .
‘Reply-To: webmaster@example.com’ . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();

$result = mail($to, $subject, $message, $headers, “-fwemaster@example.com”);
echo $result;
?>

In the mail header we can see the return path as wemaster@example.com

Delivered-To: unnikrishnan.a@gmail.com
Received: by 10.90.26.7 with SMTP id 7cs24300agz;
Thu, 9 Aug 2007 07:12:35 -0700 (PDT)
Received: by 10.115.77.1 with SMTP id e1mr1363695wal.1186668755167;
Thu, 09 Aug 2007 07:12:35 -0700 (PDT)
Return-Path: <wemaster@example.com>

Created and maintained by Unnikrishnan
Hosted by Host cats