PHP Interview Questions - III
What is a PHP Session?
PHP session allows you to store the user session, like their information on server for faster access and for later use like username, IP addresses, their actions etc. The information which is saved is temporary and can be deleted after the user is no longer active. Example of starting a PHP session is as follows:
<?php
session_start( ); // start up your PHP session!
$_SESSION['user']="Premjith"; // store session data
$a=$_SESSION['user'] // retrieve session data
unset($_SESSION['user']); // for unsetting session variable
session_destroy( ); //for destroying the session
?>
What is meant by PEAR in php? What is the purpose of it?
PEAR stands for "PHP Extension and Application Repository".
As the name suggests, it gives advanced functionality to the PHP language and include many applications which can be used on fly. The purpose of it is as follows:-
- Open source structured library for PHP users.
- Code distribution and package maintenance system.
- Standard style for code written in PHP.
Is PHP a loosely Typed Language? What is the difference between strongly typed and loosely typed language?
Yes, PHP is a loosely typed language. In this type of language variable doesn’t need to be declared before their use. This language converts the data according to its given value. Whereas, in strongly typed language first every type has to be declared (defined) then only it can be used.
What do you mean by Persistent Cookie?
A cookie which is stored in a cookie file permanently on the browser’s computer.
Explain the "unlink" and "unset" functions.
unlink( ) function is for file system handling. It just deletes the file in context.
unset( ) function is for variable management. It makes a variable undefined
What is the default session time in PHP?
Until closing the browser.
How Can we kow thediiferent betweeen two days?
The start date
and end date can be first found as shown below:
$date1= strtotime($start_date);$date2= strtotime($end_date);
$date_diff = (($date1)- ($date2)) / (60*60*24)
lets look at an example:
$date1 = "2007-03-24";
$date2 = "2007-04-26";
$diff = abs(strtotime($date2) - strtotime($date1));
echo("diff = ".$diff);
$years = floor($diff / (365*60*60*24)); //that is 31536000(365*60*60*24) seconds in an year
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d days\n", $years, $months, $days);
No comments:
Post a Comment