Pages

Friday, February 25, 2011

Session handling solved.....


Hi....
 Handling a sesion is always an important issue.

Normally errors will be thrown in default, when there is an issue or errors in sessions handling but sometimes this may not work.

One of that is what we came across recently
When we developed a website in our home country and the servers also resides in same place there is no errors or warnings related with sessions.
But after we shift the server to other country it started to throw warning like
"Session alreday created" even after we cleared old sessions using ob_start();
and started a new session
session_start();

the warnings occured because these functions were declared after some PHP coding
but the same code never thrown any warnings ever in local(the server when it is in home country).

Tips:
1. You can avoid showing unwanted warning/errors by using error_reporting(0)

So next time you got error or warning check you have called these functions at the beginning of the file.

Date and timezone issue solved



Hi....
I just faced an important problem when developing a website in PHP where the server

resides in one country and used in another.

The situation is this,
We have developed the website for indian users which resided in indian server
Recently we have changed this server to US.
The website is based on lots of date related functionalities  such as Calendar, Record

Created Date, Updated Date, History,etc,.
Since the server resides in US and the website really used and developed in India,

because of that, the results were shown with false data to the users of india wherever

date is displayed.

After sometime i found a solution

The solution to this would be using the timezone i.e

date_default_timezone_set("Asia/Calcutta") but even this will not solve all the issues

especially when you are inserting a date into the DB directly for eg using now()

"insert into tbloutgoing set sent_date=now()";

executing the above query will insert date and time of the US even you set the dafault

timezone but why, because the defualt_timezone is a function inside PHP not the server

function, the above query will execute inside phpmyadmin which is in US so the error,
This has two solutions,

The Easy way
1.You need to use timezone functionality
 Storing the date to a variable and inserting
    eg:
$mydate = date('Y-m-d');
"insert into tbloutgoing set sent_date='".$mydate."'";

The hard way
2.For this you need not use the timezone functionality.
 First you have to find the difference of time i.e US and India

Once you find it you can insert the date directly into the DB
   eg:
"insert into tbloutgoing set sent_date=now()+5.30";

Tips
1. include the timezone functionality.

Advantages of using easy way
1. You can shift the server to any country at anytime, and you need to change only the

timezone and in only one place.

Disadvantage of using the hard way
1.Shifting the server to another country.
   This would be a great disadvantage of using the hard way which may consume lot of

time, you have to find the difference and change it whereever you used date

functionality.


But i really wounder why this basic and important functionality doesnot exists  as a

default function in server.