Php Interview Questions

We have covered PHP interview questions in an easy way so that any fresher or experienced developer gets information from these questions. we define each and every topic with an example so that any reader understand easily.

Q1: What is Php?

PHP stands for Hypertext Preprocessor. PHP is a server-side scripting language that is used to develop dynamic websites. Php is an open-source technology so you can free download through the internet.

Q2: Difference between php4 and php5?

php5 is upgrade version of php4 and php5 improved object orientated programming features.

Q3: How to retrieve the data in the result set?

There is four methods to retrieve the data in the result set of MySQL using PHP.
(i) mysql_fetch_row():- this function fetches one row from a result-set and returns it as an enumerated array.

(ii) mysql_fetch_array():- this function Fetch a result row as an associative array, a numeric array, or both.

(iii) mysql_fetch_assoc():- this function Fetch a result row as an associative array.

(iv) mysql_fetch_object():- this function Fetch a result row as an as an object.

Q4: How to submit form without a submit button?

This is very simple because we can use through javascript function.


Q5: What is session?

Ans:- A session is a way to store information (in variables) to be used across multiple pages.
sessions are stored on the server.

Q6: How to create a session?

Ans:- We can create session through session_start() function

Q7: How to set a value in session?

Ans:- We set the value like this $_SESSION[$name]=$value;


Q8: How to remove data from session?

Ans:- We can remove data through unset function.


Q9: How to get the value of current session id?

Ans:- session_id() returns the session id for the current session.


Q10: How to change session id on the page?

Ans:- We can change session id through session_regenerate_id(true) function.


Q11: How to destroy all session data?

Ans:- We can destroy all session data through session_destroy(void) or session_unset(void); function.


Q12: What is the default session time in php?

Ans:- The default session time in php is until closing of browser.

Q13: What is cookie?

Ans:- Cookies works on client side and it is stored on the user’s browser.

Q14: What is the meaning of a Persistent Cookie?

Ans:- A persistent cookie is permanently stored in a cookie file on the browser’s computer. By default, cookies are temporary and are erased if we close the browser.

Q15: How to set cookies in PHP?

Ans:- We can set cookie through setcookie($cookie_name,$cookie_value,$time) function.

setcookie("username", "John", time()+3600);

Q16: How to retrieve cookies value in PHP?

Ans:- We can retrieve cookie through $_COOKIE[$cookie_name].

echo $_COOKIE['username']; //output:-John

Q17: How to remove cookie in PHP?

Ans:- We can remove cookie through set the expiration date in the past.

setcookie("username", "", time()-3600);

Q18: What is Server?

$_SERVER is an array containing information such as headers, paths, and script locations.

Q19: How to get IP address of client?

Ans:- We can get through


Q20: How to get previous reference page?

Ans:- We can get through


Q21: How to get browser property?

Ans:- We can get through


Q22: How to get server name?

Ans:- We can get through


Q23: Differences between?

1) echo and print
2) include(), include_once(), require(), require_once()
3) print_r() and var_dump()
4) unlink() and unset()
5) GET and POST method
6) Split and Explode
7) array_merge() and array_combine()
8) urlencode and urldecode
9) $variable and $$variable
10) strstr() and stristr()