PHP Interview Questions

PHP Interview Questions | Freshers & Experienced

  • Ketan Chauhan
  • 02nd Dec, 2019

PHP Interview Questions

Q1. What is mvc in PHP?

MVC is a design pattern for creating applications that separate Business logic (Controller) and Application data (Models) from the USER interface (View). MVC is an acronym of Model, View Controller.

Q2. Write a program to upload files using curl

Q3. What is name of max execution time constant in php?

max_execution_time is of the constant that is used to increase the execution time of a script in PHP.

Q4. What is difference between echo and print in PHP?

 There are small difference between Echo and Print in PHP. 

 These are - 

  1. Echo has no return value while Print has a return value of 1.
  2. Echo is marginally faster in comparison of Print.
  3. Echo can output one are more strings while Print can output only 1 string.
  4. Echo is a language constructor while Print is a function.

Q5. What is HTML DOM?

DOM (Document Object Model) is a Object Model for HTML. The Document Object Model (DOM) defines the logical structure of documents and the way a document is accessed and manipulated.

Q6. How to create cookies via Ajax in PHP?

Q7. What is sql injection? What you do to prevent SQL Injection in PHP?

The injection attacks that are used to possibly lead to the execution of an otherwise highly malicious SQL statement is known as SQL Injection.

The reports can control a database server behind a web application to cross its security measures. It can be used toad, modify and delete records in the application database. It can also be used to gain unauthorized access to your most sensitive data or information. These attacks are the most prevalent, oldest and very risky and dangerous web application vulnerabilities.

It can be prevented in PHP by using prepared statements and parameterized queries. These SQL statements are sent to and parsed by the application database server separately from any this way, it makes it impossible for attackers to inject a malicious SQL INJECTION.

Q8. Explain scope levels in PHP.

There are 3 different levels of Scopes are available in PHP. They are.

  • Public: Public scopes allow you to access all data and functions of a Class.
  • Private: Private scopes don't allow you to access the private data and functions of a Class.
  • Protected: Protected scopes only allows its derived class to access the Protected data and functions of a Class.

Q9. Find the longest palindrome in a string

Q10. What is difference between session and cookie?

The Major difference between sessions and cookies are - 

  1.  Sessions are stored in Server Side while Cookies are sotred in Client Side.
  2.  Sessions are stored unlimited amount of Data while Cookies are Stored limited amount of Data.
  3.  Sessions are holding multiple variables while Cookies are not holding multiple varibles.
  4.  Sessions are more secure than Cookies.
  5.  Sessions values are not easily accessible While Cookies values are easily accessible.
  6.  Sessions can not disabled by visitor while cookies can disabled by the visitor.

Q11. How to get IP address of user in PHP

In your code simply use  $_SERVER['REMOTE_ADDR'] to get the IP address of the client or User.

Q12. What is the full form of PHP?

The full form of PHP is Hypertext preprocessor (earlier called personal home page)

Q13. How to create object of Interface?

Q14. What is cross site scripting and how it can be prevented?

Q15. Write pyramid structure without using PHP function ?

Q16. What is difference between XAMPP, WAMP, and LAMP

Difference between XAMPP, WAMP, and LAMP

XAMPP is an open-source platform that is one of the simplest and light-weighted local servers useful to develop/test our website locally. XAMPP stands for cross-platform, Apache, MariaDB (MySQL), PHP and Perl. It can work with all major operating systems such as Windows, Mac, Linux, etc. We can perform testing and update the contents in our websites testing locally. It is open-source which can be easily downloaded and installed in our computer system.

WAMP uses the Apache webserver that is used to run a web server on windows. WAMP stands for Windows, Apache, MySQL, and PHP. It works on only the windows operating system. It uses the MySQL relational database management system and PHP object-oriented scripting language, which helps to test the web pages without publishing it on the live web server.

LAMP platform has four layers, also known as a LAMP stack. LAMP stands for Linux, Apache, Mysql, and PHP. It works on the Linux operating system. It is easy to code with PHP and a cheap and ubiquitous hosting platform. It can generate dynamic web pages that run PHP code and load data from a MySQL database.

Q17. Tell me few diffrence between GET & POST

Few difference between GET & POST is - 

GET request remains in browser history while POST Request does not remain in browser history.

GET is availbale for retrieving data while POST is available for writing/Updating data.

GET have no side effects while POST have some side effects.


Q18. How to connect MongoDB using PHP?

Q19. What is default session time in PHP? How to increase It?

Q20. How can you connect a web page data with mysql ?

Q21. Explian the difference between preg_Match and preg_replace?

preg_Match is the pattern, that is used for searching as a string, while preg_replace is the pattern, that contains the string which is used to search the content, which can be the array of string.


Q22. List the HTTP methods avalable in PHP?

Q23. What is Interface? Why we use it?

In the concept of object-oriented programming, Interfaces are used for the implementation of multiple inheritances. In simple words, it means it is a point or a place where two systems, organizations, subjects etc. meet and interact with each other. It is advantageous to increase the readability of the codes . It helps to decrease class LOC. Here, we just declare the procedure or methods and does not provide any implementation for the same. They are more flexible than Classes. They are helpful when we can’t use class inheritance. For the achievement of total abstraction, we need interfaces. Loose coupling is also achieved through it. It gives us more capability to extend and maintain our applications, utilization of abstraction and implementing good software development practices.

Q24. What is difference between PHP 4, 5 and 7?

Difference between PHP4, PHP5, and PHP7

PHP 4:

  • Here everything, including objects, is passed by value. We have to copy the code and assign a new value if we want to duplicate an object.
  • Here, the constructor is just a method with the same name as the name of the class.


  • Here, everything is passed by reference only.
  • It has three levels of visibility of class methods and properties namely public, protected and private.
  • It has a unified name for the constructors -"construct()" and also a "_destruct()"
  • We can also create abstract classes.
  • Limited type hinting, E_STRICT error level, etc are included for a better experience.


  • It allows the user to declare the return type of the functions as per the expected return value.
  • Introduction of new Engine Exception Objects.
  • It offers an anonymous class to speed up the execution time.
  • It has the Group Use Declaration through which we can include classes from the same namespace.

Q25. What is difference between the include(), require(),require_once() functions in PHP?

Q26. What are design patterns in PHP? Can you list few.

Q27. What are Super Global variables in PHP?

Q28. What is Php ini?

Q29. Code to send a mail with attachment using phpmailer?

Q30. What is difference between CURL and AJAX?

Difference between CURL and AJAX


  • It refers to the client-side utility to call PHP and extract data from it.
  • It is asynchronous and a client-side call which means until the client loads the page,it will not be executed.
  • It is used for communication from the client to the server.


  • It refers to the Client URL that helps us to connect with other URLs and apply their responses in our codes.
  • It is a package name useful in PHP in order to access data from outside webpages.
  • It is a process from server-side that is it makes requests to external websites and get a response in our background PHP script on the server.

Q31. How to set and Get a value in PHP Session.

Q32. What is the usage of link() in PHP?

PHP link() function is used to hard link for a specified target. The link function takes two arguments first is the target file and the second argument is the name of the link.

Note: The link() function does not work remotely.


$target = "abc.php";
$linkname = "name of link";
link($target, $linkname);

Q33. PHP resembles syntax from which programming Lanaguage?

PHP resembles its syntax from C and Perl Programming Language.

Q34. What is the default session path in PHP?

The default PHP session storage path on the server is /tmp directory.

About Author :

  • Author of PHP Interview Questions

    Ketan Chauhan

    Ketan is a Software developer from Bengaluru, Karnataka, India.He works on latest Javascript technologoies like Angular, Node JS, React JS. He has also good knowledge of PHP and its frameworks like CodeIgniter, CakePHP,Laravel, Zend.He is always ready for learning new technologies. He loves playing Table tennis, watching and answersing developers queries.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.

Explore Popular Courses on Php

Start working with Landrick that can provide everything you need to generate awareness, drive traffic, connect.

Laravel for beginners v6
  •  3.9 Star (10)
  • Udemy