Skip to main content

Basic Interview Questions in PHP

5 Interview questions on PHP you should know if you have mentioned PHP in your resume before going for Interviews. These are the basic but important questions and it is most frequently asked in interviews. So you should be very clear in those concepts.

1) Sessions Variables 

a) Definition: Sessions variables are used to store user information on the internet temporarily so that this user information can be used on multiple pages of the website.

b) Why do we need it? : As the Web server doesn't maintain a state so it doesn't know who you are and so it needs some variable to store your information.

c) What is the user information we are talking about ?: User information are mainly username, Password or any other data user is using on one page and can be used in other web pages as well of the same website.

d) How session variable work? : The session variable basically works by creating a unique session ID for users and then using this ID on different pages of the website. This ID is generally stored in cookies or propagated through the URL of the website

e) How to use session variables in PHP to store information? :

<?php
session_start();          // Start session
$_session['info']=1    // Store value or info in session variable
session_destroy();     // Destroy the session
<?
you can use $_session['info'] across multiple pages of website.

2) Cookie

a) Definition: A cookie is a small file with a user information server stored on the user browser so that each time the user request the same web page through that browser, the server will identify the user.

b) How is it different from the session? : It is different from the session in a way that it stores the user information in client-side such as browser but the session stores user information on the server. The cookie will remain stored in your browser until you delete your cookies but stored info in session will be lost as soon as you closed the website.

c) How to use cookies in PHP? :

setcookie(name,value,expire,path,domain)

<?php
setcookie("info", "123",time()+3600)
echo $_cookie['info'];
?>

Here expire is the time in which you want the cookie to get expire.

3) POST vs GET in PHP form handling

Both POST and GET are method to send information or values from form to other PHP page.

GET : Information sent from GET method is visible to everyone as it embeds values at the back of the URL so it should not be used for sending some secret information like username and password using GET. And also through GET method, you cannot send unlimited information using GET only 2000 characters are allowed to send. As the values are stored in the URL we can bookmark the page.

POST: Information sent through POST is invisible to everyone as it is embedded in the HTTP request body. There is no limit to sending information in POST. We cannot bookmark the page as the information is not stored in the URL.

4) Include vs Require in PHP

Both Include and require are used to include the content or code of the other PHP page on the given page.

Include: Include will give a warning if some fatal error occurs and continue the script. So if you want the output in the end-use include

Require: Require doesn't give a warning if some fatal error comes it stops the script then and there. So if you are making some complex PHP page or application it is advisable to use required.

5) PHP upload 

PHP upload is used to upload files on the server

A simple PHP script to upload the file1 to server displaying its name.type and size

HTML 

<form enctype="multipart/form-data"   action="upload.php"   method="post">
<input type="file" name="file1" id="file1">
<input type="submit" value="submit">
</form>

Here enctype="multipart/form-data" is used to show the type of file.

PHP

upload.php

<?php
if ($_FILES["file1"]["error"] > 0) {
  echo "Error: " . $_FILES["file1"]["error"] . "<br>";
} else {
  echo "Upload: " . $_FILES["file1"]["name"] . "<br>";
  echo "Type: " . $_FILES["file1"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file1"]["size"] / 1024) . " kB<br>";

}
?>

Also, See How to fetch documents from remote addresses using PHP and PHP array Functions

Comments

Popular posts from this blog

Tricky Questions or Puzzles in C ( Updated for 2026)

Updated for 2026 This article was originally written when C/C++ puzzles were commonly asked in interviews. While such language-specific puzzles are less frequent today, the problem-solving and logical reasoning skills tested here remain highly relevant for modern Software Engineering, Data Engineering, SQL, and system design interviews . Why These Puzzles Still Matter in 2026 Although most Software &   Data Engineering interviews today focus on Programming, SQL, data pipelines, cloud platforms, and system design , interviewers still care deeply about how you think . These puzzles test: Logical reasoning Edge-case handling Understanding of execution flow Ability to reason under pressure The language may change , but the thinking patterns do not . How These Skills Apply to Data Engineering Interviews The same skills tested by C/C++ puzzles appear in modern interviews as: SQL edge cases and NULL handling Data pipeline failure scenarios Incremental vs ...

Programs and Puzzles in technical interviews i faced

I have attended interview of nearly 10 companies in my campus placements and sharing their experiences with you,though i did not got selected in any of the companies but i had great experience facing their interviews and it might help you as well in preparation of interviews.Here are some of the puzzles and programs asked to me in interview in some of the good companies. 1) SAP Labs I attended sap lab online test in my college through campus placements.It had 3 sections,the first one is usual aptitude questions which i would say were little tricky to solve.The second section was Programming test in which you were provided snippet of code and you have to complete the code (See Tricky Code Snippets  ).The code are from different data structures like Binary Tree, AVL Tree etc.Then the third section had questions from Database,OS and Networks.After 2-3 hours we got the result and i was shortlisted for the nest round of interviews scheduled next day.Then the next day we had PPT of t...

Program to uncompress a string ie a2b3c4 to aabbbcccc

Below is the program to uncompress a string #include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { char str[100]="a2b3c4d8u7"; for(int i=0;str[i]!='\0';i++) { if(i%2!=0) { for(int j=0;j<atoi(&str[i]);j++) { printf("%c",str[i-1]); } } } getch(); } Want to become a Data Engineer? Check out below blog posts  1.  5 Key Skills Every Data Engineer needs in 2023 2.  How to prepare for Data Engineering Interviews 3.  Top 25 Data Engineer Questions