PHP Interview Questions -5

PHP Interview Questions -5

1. What is PHP stands for?

Hyper text Pre Processor

2. What is PHP?

The PHP is a Hypertext Pre-processor and is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.

3.Who is the Father of PHP?

Rasmus Lerdorf

4.Which programming language does PHP resemble to?

PHP resemble to pearl and C

5. What the difference is between include and require?

Require () and include () are the same with respect to handling failures. However, require () results in a fatal error and does not allow the processing of the page. i.e. include will allow the script to continue.

6. What is the current version of PHP?

php 5.3

7. How can we create a database using PHP and MySQL?

We can create MySQL database with the use of
mysql_create_db ("Database Name")

8.What Is a Session?

It can be used to store information on the server for future use.

9. Is variable name case sensitive?

Yes variable name case sensitive and we cannot start a variable with number like $6name as a valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

10. How can we execute a php script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.

11. Why is PHP-MySQL used for web Development?

We use PHP-MySQL in web development because both are open source means both free to use. Both when MySQL work with PHP it gives result much faster than when MySQL work with Java/.Net/Jsp.  

12. What function we used to change timezone from one to another ?

I have given you a function using them we can change a timezone into another timezone.
date_default_timezone_set() function
And we use date_default_timezone_get() function to get the entered date.

13. How do you understand about stored procedure,Triggers and transaction in php?

Below I have given how stored procedure,Triggers and transaction work in PHP:
1.Stored Procedure: It is combination of some SQL commands it is stored and can be compiled.Suppose that when user is executed a command than user has don't need to reissue the entire query he can use the stored procedure.Basically main reason to use the stored procedure is that using this we can decrease the time of reissue of that query. Because work done on server side is more than the work done on application side.
2.Trigger: Trigger is a stored procedure.This is used to work stored procedure effectively.It is invoked when a special type of event comes.For effectively understand this i have given you a example.
When we attach a trigger with stored procedure than when we delete a record from transaction table than will automatically work and delete the respective client from client table.
3.Transaction: Transaction is that in which particular amount of data goes from the a client to the another client.We maintain the transaction record into a table called transaction table. 
14.How we can upload videos using PHP?

When want to upload videos using PHP we should follow these steps:
1.first you have to encrypt the the file which you want to upload by using "multipart-form-data" to get the $_FILES in the form submition.
2.After getting the $_FILES['tmp_name'] in the submition
3.By using move_uploaded_file (tmp_location,destination) function in PHP we can move the file from original location.

15. How can we create a database using PHP and myqsl?

I have given you a example using this you can create a database.
$con =mysql_connect("localhost","vivek","vivabh");
if (!$con)
     die('Could not connect: ' . mysql_error());
if (mysql_query("CREATE DATABASE my_db",$con))
     echo "Database has been created";
     echo "Error to create database: " . mysql_error();

16. What do you understand about Joomala in PHP?

Joomala is an content management system who is programmed with PHP.Using this we can  modified the PHP sit with their content easily.

17. How you can differentiate abstract class and interface?

There are some main difference between abstract and interface are given below:
1.In an abstract we can use sharable code where in the case of interface their is no facility to use sharable code.
2.In which class we implement an interface class. All method that we use should be defined in interface. Where as class those extending an abstract while a class extending an abstract class their is no need to defined methods
in the abstract class.

18. What do you understand about Implode and Explode functions?

The main difference b/w Implode and Explode functions is that We use Implode function to convert the array element into string where each value of array is separated by coma(,).
$array = array('First_Name', 'Email_Id', 'Phone_NO');
$comma_separated_string = implode(",", $array);
echo $comma_separated_string;
 We use Explode function to convert the string value those are separated with coma(,) into  array.
$comma_separated_string = string('First_Name,Email_Id,Phone_No');
$array = Explode(",", $coma_separated_string);
echo $array;

19. Can we submit a form without submit button?

Using JavaScript we can submit a form without submit button.
document.FORM_NAME.submit();//this is used to submit the form

20. Can I develop our own PHP extension?if yes,how?

Yes,we can develop a PHP extension like that,
echo 'PHP';
 To save this file as .php extention

21. What do you understand by nl2br()?

nl2br() function is stands for new line to break tag.
echo nl2br("R4R Welcomes\nYou");
R4R Welcomes

22.How function strstr and stristr both work in PHP?

Generally, Both function strstr and stristr are same except one thing stristr is a case sensitive where as strstr is an non-case sensitive.We use strstr to match the given word from string.
strstr(string,match word)
$email_id = '';
$id_domain = strstr($email_id, '@');
echo $id_domain;

23. In PHP can I get the browser properties?

Using get_browser function we can get the browser properties in PHP.
$browser_properties = get_browser(null, true);

24. How we can increase the execution time of a PHP script?

I have given you some function using them you can increase the execution time of a PHP script.Default time for execution of a PHP script is 30 seconds.
These are,
1.set_time_limit()//change execution time temporarily.
2.ini_set()//change execution time temporarily.
3. By modifying `max_execution_time' value in PHP
configuration(php.ini) file.//change execution time permanent.

25. How we can get the value of current session id?

We can get the value of our current session id by using session_id().It returns the value of our current session id.

26. How we use ereg_replace() and eregi_replace()in PHP?

The main difference b/w ereg_replace and eregi_replace() is that,eregi_replace is case sensitive. Example:In eregi_replace() it think both \'welcome\' and \'WeLCome\' are different. where as ereg_replace() is not case sensitive.

Example:In ereg_replace() it think both \'welcome\' and \'WeLCome\' are same.

27. Which type of inheritance exists in PHP?

PHP supports Multi-level inheritance.It doesn't support multiple inheritence.But using interface  we can achieve multiple inheritance in PHP.

28. What do you understand about pear in PHP?

Basically PEAR is stands for PHP Extension And Repository.PEAR is a framework and distribution system using that we can make PHP component reusable.It has huge collection of different classes.We use this for advance scripting.Example: Database,Mail,HTTP etc.

29. Tell me how to use COM components in PHP?

We use COM component in PHP by using that manner,



$objCom = new COM(├»¿½AddNumber.math├»¿½);

$output = $objCom ->AddTwoNum(4,5);

echo $output;


30. Tell me default session time in PHP and how can I change it?

The default session time in PHP is 14400.We can change it like that manner,




31. How we use copy() and move() file uploading functions in PHP?

When we use copy function it copy the file from source location to destination location and keep original file to the source location.


copy($_FILES['uploadedfile']['tmp_name'], $destination_path)

Where as when we use move function it copy the file from source location to destination location and delete original file from source location.


move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $destination_path)

32. How can we find out the name of the current executing file?

I have given you a example that gives you the name of current executing file,



$File_Name = $_SERVER["SCRIPT_NAME"];

echo $File_Name;


33. What is the main difference b/w include_once() and require_once() in PHP?

The main difference b/w include_once() and require_once() is that, In PHP if file is not exist and specified with include_once() it gives show warning message.Where as if we specified file as require_once() it giver a fatal error.

34. what are the constant value in PHP?can we write them without $ symbol?

We can't change the value of constant.Yes,we can write constant value in PHP.Below I have given you a example:
define("CONSTANT","R4R Welcomes You");
echo "CONSTANT";

35. Explain the difference between $message and $$message?

$message is used to store variable data. $$message can be used to store variable of a variable. Data stored in $message is fixed while data stored in $$message can be changed dynamically.
E.g. $var1 = ‘Variable 1’
$$var1= ‘variable2’
This can be interpreted as $ Variable 1=‘variable2’;
For me to print value of both variables, I will write
$var1 $($var1)

36. What is session hijacking?

Session hijacking is the misuse of a valid computer session. It is used to attain unauthorized and illegal access to a system. This access is attained using the “brute force” attack where in he tries multiple id’s to login in a system while the session is in progress. The most common method of session hijacking is IP spoofing where an attacker uses source-routed IP packets to insert commands into an active communication between two systems on a network and pretending itself as one of the authenticated users.

37. How session will work when we disable cookies of client browser?

Session is kind of cookie who is work on server side.For working of session on server side cookies should be enable on server side and also on client side browser.But session will also work when cookies are disable on client side by using URL session passing.

38. Explain about PHP cookies?

A cookie is a small piece of information that is generated by the server but stored on the client. In php $_COOKIE['name'] is used to access a particular cookie.

39.What is a PHP accelerator?

PHP accelerator increases the speed of applications written in PHP. This boost of performance can be around 2-10 times. PHP accelerator increases the speed of the applications by decreasing parsing each and every time a PHP application runs. It depends upon factors such as time taken for execution of the PHP script and the actual percentage of the source code requested.

40.Explain about the data types in PHP?

Actually we have 7 data types are there in php.
1.Integer 2.Float 3.String 4.Object 5.Array 6.Boolean 7.Resource

41. What is Object Oriented Programming?

This is usually a pretty open ended question. You should understand classes (objects are instantiated classes), abstract classes, interfaces, methods, properties,inheritance, multiple inheritance as well as why OOP is helpful as compared to procedural programming.

42. In PHP what is the difference between a Class and an Interface?

Interfaces do not contain business logic, only method signatures that define a template that any classes implementing the interface must contain. Lets take an auto mobile for example. If we were to create and interface for a car we would want to define a few methods like drive, stop, turn left , turn right. This mean that any vehicle that is a car (aka implements the interface car) must have methods for these things, If they do not PHP will throw an error. So if your car is an BMW , Honda or Ford it must be able to stop. How it stops is up to each car (or PHP class) but it must be able to stop. Technically we can decided not to use an interface for cars, but then some types of cars are not forced to have a "stop" method.

43.What is MVC?

Most programmers know this, but interviewers will likely look for a deep understanding of MVC, and some explanation or examples on how/why/ when you used it.

MVC- Model, View, Controller - is simply a way of organizing your code into 3 separate layers each with there own jobs.

Model - Usually contains data access code and all of you business logic code.
View - Contains markup/design code, generally html,xml, json.
Controller - Usually contains very little code, just whatever is needed to call the Model code and render the View code.

44.Explain how a PHP session works?

A PHP session cookie is set in the clients browser, on every request the client sends that cookie to the server. PHP then uses that cookie to select the corresponding session information. By default PHP session_start() will store session data in files, you can also store sessions in a database.

45. What are some of the big changes PHP has gone through in the past few years?

There are a number, but the big ones people are looking for are:
a. PHP 5.0 realised the object model (AKA OOP).
b. 5.1 added PDO - for accessing databases.
c. 5.3 - added namespace support and late static bindings.

46.What is the difference between $_GET and $_POST

This is a great question because an interviewer can tell how deeply you understand HTTP and the request/response. If you don't have good understanding of HTTP protocol, google around and get a grasp on it.

47. In a PHP class what are the three visibility keywords of a property or method?

public, private and protected. The default is public.
Public -> Any class may instantiate the class and call the method or property.
Protected -> Only the class itself or inherited (children) classes may call a method or property.
Private -> Only the class itself may call a method or property.

48.  What is Polymorphism?

Don't get scared by the big word. It's simply the idea that one object can can take on many forms. So in PHP OOP one class "cars" may have two classes that extend it, for example a "Honda" class and a "BMW" class.

49.  How do you load classes in PHP?

They are trying to gauge your understanding of how class auto loading works. Review the "autoload" and "spl_autoload_register" function (note:you should us the later). The autoload function basically triggers a function when a class is instantiated, you can put whatever logic you like in it but generally you want to include the class file based on some sort of naming convention.

50. What is the value of "$day" in the below code?

$wed= 1;   
$day = ($wed==1) ? 'today' : 'tommorrow';
// $day is now set to 'today'

Companies often ask about the ternary operator (?). which is simply a shorthand for if else statements.

51.What is the Scope Resolution Operator?

"::" double colons is the scope operator it is used to call methods of a class that has not been instantiated. You should also understand static methods and how they differ from regular methods.

52. What are some PHP Design patterns you have worked with?

Design patterns are simply commonly used techniques within your code, they often are implemented in different ways so they can be a bit tricky to grasp without writing them yourself. If you are unfamiliar with them I would start by learning the Singleton Pattern and the Strategy Pattern.

53. What is the difference between single quotes and double quotes?

Great answer at below link.

54. What does ob_start do?

Makes it so PHP does not output anything. Companies ask this because many large frameworks wrap a bunch of code in ob_start() and ob_get_clean(). So understanding how that function works is pretty important.

55. What does "&" mean in '&$var' ?

'&' indicates a reference

56. What is the meaning of a final class and a final method?

Final keywords indicates that the class or method cannot be extended.

57.  Does PHP support multiple inheritance?

No. You should understand what multiple inheritance is.

58. What are some magic methods in PHP, how might you use them?

Magic methods are basically triggers that occur when particular events happen in your coding. __GET, __SET are magic methods that are called (behind the seen) when you get or set a class property.

59. What is the difference between $var and $$var?

$$var sets the value of $var as a variable.

            $$day='first day of week';
            echo $monday; //outputs 'first day of week'
60.What is the difference between the functions unlink and unset

unlink() is a function for file system handling. It will simply delete the file in context.unset() is a function for variable management. It will make a variable undefined.
61.What are encryption functions in PHP Discussion

CRYPTO(), SHA1(), MD5()-

62.What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()

1:mysql_fetch_array() -> Fetch a result row as a combination of associative array and regular array.mysql_fetch_object() -> Fetch a result row as an object.mysql_fetch_row() -> Fetch a result set as a regular array().Answer 2:The difference between mysql_fetch_row() and mysql_fetch_array() is that the first returns the results in a numeric array ($row[0], $row[1], etc.), while the latter returns a the results an array containing both numeric and associative keys ($row['name'], $row['email'], etc.). mysql_fetch_object() returns an object ($row->name, $row->email, etc.).

63. How can we find the number of rows in a result set using PHP

Here is how can you find the number of rows in a result set in PHP:$result = mysql_query($any_valid_sql, $database_link);$num_rows = mysql_num_rows($result);echo "$num_rows rows found";

64.How do you call a constructor for a parent class


65.How To Assigning a New Character in a String using PHP

we can use str_replace function.


$string = 'Hello';

$alteredString = str_replace('e', 'i', $string);

echo $alteredString;

O/P : Hillo

66.How can we encrypt and decrypt a data present in a mysql table using mysql


67. How can we find the number of rows in a result set using PHP

Here is how can you find the number of rows in a result set in PHP:$result = mysql_query($any_valid_sql, $database_link);$num_rows = mysql_num_rows($result);echo "$num_rows rows found";

68. How do you call a constructor for a parent class


69. How many values can the SET function of MySQL take

MySQL SET function can take zero or more values, but at the maximum it can take 64 values.

70. What is meant by nl2br() Discussion

nl2br() inserts a HTML tag <br> before all new line characters n in a string.echo nl2br("god bless n you");output:god bless<br>you

71. How To Check Your PHP Installation Discussion

PHP provides two execution interfaces: Command Line Interface (CLI) and Common Gateway Interface (CGI). If PHP is installed in the php directory on your system, you can try this to check your installation: * Run "phpphp -v" command to check the Command Line Interface (CLI). * Run "phpphp-cgi -v" command to check the Common Gateway Interface (CGI).If you see PHP printing the version information on your screen for both commands, your installation is ok. Open a command window and run the commands below:C:>phpphp -vPHP 5.2.2 (cli) (built: May 2 2007 19:18:26)Copyright (c) 1997-2007 The PHP GroupZend Engine v2.2.0 Copyright (c) 1998-2007 Zend TechnologiesC:>phpphp-cgi -vPHP 5.2.2 (cgi-fcgi) (built: May 2 2007 19:18:25)Copyright (c) 1997-2007 The PHP GroupZend Engine v2.2.0 Copyright (c) 1998-2007 Zend Technologies

72. What is the difference between include and require

It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

73. What changes I have to do in php.ini file for file uploading

Make the following line uncomment like:; Whether to allow HTTP file uploads.file_uploads = On; Temporary directory for HTTP uploaded files (will use system default if not; specified).upload_tmp_dir = C:apache2triadtemp; Maximum allowed size for uploaded files.upload_max_filesize = 2M

74. How can we change the name of a column of a table

This will change the name of column:ALTER TABLE table_name CHANGE old_colm_name new_colm_name

75. How can we create a database using PHP and MySQL?

We can create MySQL database with the use of mysql_create_db("Database Name")

76. How can I execute a PHP script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument.

77. what is meant by nl2br()?

Inserts HTML line breaks (<BR />) before all newlines in a string.

78. How can we encrypt and decrypt a data present in a MySQL table using MySQL?

79. How can we encrypt the username and password using PHP?

The functions in this section perform encryption and decryption, and
compression and uncompression:

80 What are the differences between PHP3 and PHP4 and PHP5 ? what is the current stable version of PHP ? what advance thing in php6

The current stable version of PHP is PHP 5.4.11 on 2013-01-17 as still waiting for PHP6 with unicode handlig thing
There are lot of difference among PHP3 and PHP4 and PHP5 version of php so Difference mean oldest version have less functionality as compare to new one like

81.How we get IP address of client, previous reference page etc ?

82.What are the reasons for selecting lamp (Linux, apache, MySQL,PHP) instead of combination of other software programs, servers and operating systems?

All of those are open source resource. Security of Linux is very
very more than windows. Apache is a better server that IIS both in
functionality and security. MySQL is world most popular open source
database. PHP is more faster that asp or any other scripting language.

83.What is the difference between the functions unlink and unset?

unlink() deletes the given file from the file system.
unset() makes a variable undefined.
84 .How can we register the variables into a session?

$_SESSION['name'] = "sonia";
85 .How can we get the properties (size, type, width, height) of an image using PHP image functions?

To know the Image type use exif_imagetype () function
To know the Image size use getimagesize () function
To know the image width use imagesx () function
To know the image height use imagesy() function t
86 .How can we increase the execution time of a PHP script?

by changing the following setup at php.inimax_execution_time = 30; Maximum execution time of each script, in seconds

87.What is the difference between CHAR and VARCHAR data types

CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.

88. How To Run a PHP Script Discussion

A standard alone PHP script can be executed directly with the PHP Command Line Interface (CLI). Write the following script in a file called hello.php:<?php echo "Hello world!"; ?>This script can be executed by CLI interface like this:phpphp hello.phpYou should see the "Hello world!" message printed on your screen.


Using imagetypes() function to find out what types of images are supported in your PHP engine.imagetypes() - Returns the image types supported.This function returns a bit-field corresponding to the image formats supported by the version of GD linked into PHP. The following bits are returned, IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM.

90. What are the differences between require and include, include_once

Anwser 1:require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again.But require() and include() will do it as many times they are asked to do.Anwser 2:The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include() produces a warning message whereas require() produces a fatal errors.Anwser 3:All three are used to an include file into the current page.If the file is not present, require(), calls a fatal error, while in include() does not.The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. It des not call a fatal error if file not exists. require_once() does the same as include_once(), but it calls a fatal error if file not exists.Anwser 4:File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored.

91. What is maximum size of a database in mysql

If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint. The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected.The amount of available disk space limits the number of tables.MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 – 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits.The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB.

92. What is the functionality of the function htmlentities

htmlentities() - Convert all applicable characters to HTML entitiesThis function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

93. How To Remove Leading and Trailing Spaces from User Input Values in PHP

If you are taking input values from users with a Web form, users may enter extra spaces at the beginning and/or the end of the input values. You should always use the trim() function to remove those extra spaces as shown in this PHP script:<?php$name = $_REQUEST("name");$name = trim($name);# $name is ready to be used...?>

94. How can we destroy the cookie in PHP

Set the cookie with a past expiration time.

95. How can we get second of the current time using date function

$second = date("s");

96. How To Create a Table using PHP

If you want to create a table, you can run the CREATE TABLE statement as shown in the following sample script:<?phpinclude "mysql_connection.php";$sql = "CREATE TABLE ggl_links (". " id INTEGER NOT NULL". ", url VARCHAR(80) NOT NULL". ", notes VARCHAR(1024)". ", counts INTEGER". ", time TIMESTAMP DEFAULT sysdate()". ")";if (mysql_query($sql, $con)) {print("Table ggl_links created.n");} else {print("Table creation failed.n");}mysql_close($con);?>Remember that mysql_query() returns TRUE/FALSE on CREATE statements. If you run this script, you will get something like this:Table ggl_links created.

97. How can we get second of the current time using date function

$second = date("s");

98. How can we submit form without a submit button

We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form. For example: <input type=button value="Save" onClick="document.form.submit()">

99.What type of inheritance that php supports Discussion

In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'

100.How To Convert Numbers to Strings in PHP

In a string context, PHP will automatically convert any numeric value to a string. Here is a PHP script examples:<?php print(-1.3e3);print("");print(strlen(-1.3e3));print("");print("Price = $" . 99.99 . "");print(1 . " + " . 2 . " = " . 1+2 . "");print(1 . " + " . 2 . " = " . (1+2) . "");print(1 . " + " . 2 . " = 3");print("");?>This script will print:-13005Price = $99.9931 + 2 = 31 + 2 = 3The print() function requires a string, so numeric value -1.3e3 is automatically converted to a string "-1300". The concatenation operator (.) also requires a string, so numeric value 99.99 is automatically converted to a string "99.99". Expression (1 . " + " . 2 . " = " . 1+2 . "") is a little bit interesting. The result is "3" because concatenation operations and addition operation are carried out from left to right. So when the addition operation is reached, we have "1 + 2 = 1"+2, which will cause the string to be converted to a value 1.

101.What Is the Best Way to Test the strpos() Return Value in PHP

Because strpos() could two types of values, Integer and Boolean, you need to be careful about testing the return value. The best way is to use the "Identical(===)" operator. Do not use the "Equal(==)" operator, because it does not differentiate "0" and "false". Check out this PHP script on how to use strpos():<?php$haystack = "needle234953413434516504381640386488129";$pos = strpos($haystack, "needle");if ($pos==false) { print("Not found based (==) test");} else { print("Found based (==) test");}if ($pos===false) { print("Not found based (===) test");} else { print("Found based (===) test");}?>This script will print:Not found based (==) testFound based (===) testOf course, (===) test is correct.

102.How to reset/destroy a cookie in PHP

Reset a cookie by specifying expire time in the past:Example: setcookie('Test',$i,time()-3600); // already expired timeReset a cookie by specifying its name onlyExample: setcookie('Test');

103.What Is a Persistent Cookie in PHP

A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer. By default, cookies are created as temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:* Temporary cookies can not be used for tracking long-term information.* Persistent cookies can be used for tracking long-term information.* Temporary cookies are safer because no programs other than the browser can access them.* Persistent cookies are less secure because users can open cookie files see the cookie values.

104.How many ways can we get the value of current session

session_id() returns the session id for the current session.

105.How To Protect Special Characters in Query String

If you want to include special characters like spaces in the query string, you need to protect them by applying the urlencode() translation function. The script below shows how to use urlencode():<?phpprint("<html>");print("<p>Please click the links below"." to submit comments about</p>");$comment = 'I want to say: "It's a good site! :->"';$comment = urlencode($comment);print("<p>"."<a href="processing_forms.php?name=Guest&comment=$comment">"."It's an excellent site!</a></p>");$comment = 'This visitor said: "It's an average site! :-("';$comment = urlencode($comment);print("<p>".'<a href="processing_forms.php?'.$comment.'">'."It's an average site.</a></p>");print("</html>");?>


Post a Comment