Find Interview Questions for Top Companies
Ques:- How can I get the only name of the current executing file?
Asked In :-
Right Answer:
You can get the name of the current executing file using the `basename()` function with the `$_SERVER['PHP_SELF']` variable like this:

```php
$currentFileName = basename($_SERVER['PHP_SELF']);
```
Comments
Admin May 17, 2020

<?php
//To get current file name.
$file = $_SERVER["SCRIPT_NAME"];
echo $file;
?>

Admin May 17, 2020

$file_path=$_SERVER["SCRIPT_NAME"];
$break=explode('/',$file_path);
$file_name=$break[count($break)-1];

Ques:- What are the differences between include() and include_once () functions?
Asked In :-
Right Answer:
The `include()` function includes a file every time it is called, while `include_once()` includes a file only once during the script execution, preventing multiple inclusions of the same file.
Comments
Admin May 17, 2020

include()-many time refresh
include_once-only one time refresh

Admin May 17, 2020

The include_once() function includes and evaluates the
specified file during the execution of the php script. It's
behavior is similar to the include() function but the only
difference is that if the code from a file has already been
included, it will not be included again.

Ques:- Describe the importance of DABA BASE ABSTRACTION LAYERS in PHP and database connection?
Asked In :-
Right Answer:
Database Abstraction Layers (DBAL) in PHP are important because they provide a consistent interface for interacting with different database systems. This allows developers to write code that is database-agnostic, making it easier to switch between databases without changing the application logic. DBAL also enhances security by preventing SQL injection attacks and simplifies database operations by offering higher-level functions for common tasks.
Comments
Admin May 17, 2020

Database abstraction means using a common db function for
querying. This would be great when you are switching from
one database to another. You won't have to change each and
every database function. Instead of that you can simply
change the database function names in one file. This should
be considerable, if in future you are planning to change the
database. The disadvantage of this is, it will slower down
the performance.

Ques:- What is the difference between using copy() and move() function in PHP file uploading?
Asked In :-
Right Answer:
The `copy()` function in PHP creates a duplicate of a file at a new location, while the `move()` function transfers a file from one location to another, effectively removing it from the original location.
Comments
Admin May 17, 2020

copying a file means making a duplicate copy of the file,
moving a file means to drag a file from one place to another. it will have the same effect like cut and paste.

Ques:- What is the difference between Reply-to and Return-path in the headers of a mail function?
Asked In :-
Right Answer:
The "Reply-to" header specifies the email address that replies should be sent to, while the "Return-path" header indicates where undeliverable messages should be sent.
Comments
Admin May 17, 2020

Basic difference between this both is follow:
Reply-to: It is user id at which you are send the this mail.
Return-path: It is user id at which mail are return when
mail is not reached to particular user id (reply_to id).

Admin May 17, 2020

Here's a quick explanation for all of you as who wonder why
your mail goes out as "mailbot@buzzcast.com:
Customers of buzzcast can change their list properties so
that replies are either ignored (never-never land), or your
own address.
Either way, when the mail comes in, it says
To: Your Listname
From: Reply-to Name: (mailbot@buzzcast.com)
When you opr subscriber hit "reply" on the message you've
received, it will be the buzzcast customers email
(joepayingbuzzcastcustomer@hisdomain.com) if they have
chosen NOT to ignore replies.
The return path is set to us (mailbot.. ) ALWAYS, so we can
remove bad addresses from the accounts! Spiffy, eh?
Some customers may not anticipate this, or understand the
difference between from, reply-to and return-path
addresses.
Mail formats are not too difficult, but they are designed
with products like buzzcast in mind.
Remember that users will NEVER see html, code, or personal
information about your account when you mail them. Just a
cool looking campaign.
This has been a common question for me, so I thought I
would share it!

Ques:- What are the differences between PHP3 and PHP4 versions?
Asked In :-
Right Answer:
1. **Object-Oriented Programming**: PHP4 introduced a more advanced object model with support for classes and objects, while PHP3 had a limited object-oriented approach.

2. **Performance**: PHP4 offered improved performance and speed compared to PHP3.

3. **Support for HTTP Sessions**: PHP4 introduced built-in support for session management, which was not available in PHP3.

4. **Output Buffering**: PHP4 added output buffering capabilities, allowing developers to control the output flow more effectively.

5. **Better Error Handling**: PHP4 improved error handling mechanisms compared to PHP3.

6. **Compatibility with Web Servers**: PHP4 provided better compatibility with various web servers and platforms than PHP3.
Ques:- What type of headers have to add in the mail function in which file a attached?
Asked In :-
Right Answer:
To send an email with an attachment in PHP, you need to set the following headers:

```php
$headers = "From: sender@example.comrn";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: multipart/mixed; boundary="boundary"rn";
```

The attachment handling code should be included in the same file where you call the `mail()` function.
Comments
Admin May 17, 2020

$headers = "Content-type disposition :attachmet
filename = 'filename.txt' "

Admin May 17, 2020

To attach a file we must add the following header
as "nMIME-Version: 1.0n Content-Type: multipart/mixed"

Ques:- What’s diffrence between Get() and Post() Function
Asked In :-
Right Answer:
The `GET()` function is used to send data to the server via the URL, making it visible in the address bar, while the `POST()` function sends data in the request body, keeping it hidden from the URL. Additionally, `GET` has size limitations and is generally used for retrieving data, whereas `POST` can handle larger amounts of data and is used for submitting data.
Comments
Admin May 17, 2020

<p>Get shows information travling on the address bar but post do not shows in this way the post method is more secure than get</p>

Admin May 17, 2020

As said above, i also want to include another point, through get() method we can send onnly 100 characters, so get() method as limitation on the information send. whereas post() method doesn't have any limitaions.

Ques:- List out different arguments in PHP header function?
Asked In :- creo,
Right Answer:
The `header()` function in PHP can take the following types of arguments:

1. **Status Header**: e.g., `header("HTTP/1.1 404 Not Found")`
2. **Content-Type**: e.g., `header("Content-Type: text/html; charset=UTF-8")`
3. **Location Redirect**: e.g., `header("Location: http://www.example.com/")`
4. **Cache Control**: e.g., `header("Cache-Control: no-cache, must-revalidate")`
5. **Custom Headers**: e.g., `header("X-Powered-By: PHP/8.0")`

These arguments control the HTTP response sent to the client.
Ques:- What are the Merits and De-Merits of CURL library ?
Asked In :-
Right Answer:
**Merits of CURL library:**
1. Supports multiple protocols (HTTP, HTTPS, FTP, etc.).
2. Allows for easy file uploads and downloads.
3. Handles cookies and sessions seamlessly.
4. Provides options for custom headers and user agents.
5. Supports SSL connections and authentication.
6. Can handle redirects automatically.

**De-Merits of CURL library:**
1. Can be complex for beginners due to its extensive options.
2. Requires additional installation on some servers.
3. May have performance overhead compared to simpler methods.
4. Error handling can be less intuitive.
5. Not all PHP installations have CURL enabled by default.
Ques:- Write the code for upload a video file in PHP.How will You Play this in Your Page.?
Asked In :-
Right Answer:
```php
<!-- HTML Form for Uploading Video -->
<form action="upload.php" method="post" enctype="multipart/form-data">
Select video to upload:
<input type="file" name="videoFile" accept="video/*">
<input type="submit" value="Upload Video" name="submit">
</form>
```

```php
// upload.php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$targetDir = "uploads/";
$targetFile = $targetDir . basename($_FILES["videoFile"]["name"]);
$uploadOk = 1;
$videoFileType = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));

// Check if video file is a actual video or fake video
$check = getimagesize($_FILES["videoFile"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
} else {
echo "File is not a video.";
Comments
Admin May 17, 2020

by using object and embed method
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-
444553540000"......
and
<embed src="test.wmv .......

Admin May 17, 2020

In u'r form tag keep an attribute called enc-type with
multipart/form-data
eg:
<form name="upload" id="upload" action="upload.php"
method="post" enctype="multipart/form-data">
So this makes the browser to think that the form is posting
a file as data and this file is sent as chunks, the file
details will be stored in a variable called $_FILES.
In u'r php file just use move_uplode_file("$temp name,<new
file path>")..
Also check the max file size in php.ini while uploading

Ques:- What is the advantge and disadvantage of mysql_connet() and mysql_pconnect() ? in which condition will you use mysql_connect() and mysql_pconnect().
Asked In :-
Right Answer:
**Advantages of `mysql_connect()`:**
- Establishes a new connection to the MySQL server each time it is called.

**Disadvantages of `mysql_connect()`:**
- Can be slower due to creating a new connection for every request.

**Advantages of `mysql_pconnect()`:**
- Opens a persistent connection that remains open after the script ends, which can improve performance for repeated requests.

**Disadvantages of `mysql_pconnect()`:**
- Can lead to resource exhaustion if too many persistent connections are opened, and may not close connections properly.

**Usage:**
- Use `mysql_connect()` for one-time connections where performance is not critical.
- Use `mysql_pconnect()` for applications with high traffic that require frequent database access to improve performance.
Comments
Admin May 17, 2020

If you're connecting to a MySQL database in your PHP
application, you'll find that there are two alternative
connctions - mysql_connect which establishes a new
connection "each time" and mysql_pconnect which uses
persistant connections. Which should you use?
Mysql_connect opens a new connection each time a PHP page is
called up, and closes the connection down again at the end
of the request. It's ideal for pages that don't have a heavy
usage - doesn't need tuning, is straightforward internally.
If you compare MySQL to a shop, this is the connection that
you would use for a small shop where the door is opened each
time a new customer wishes to enter.
Mysql_pconnect will also open a new connection when a PHP
page is called up (at any rate, it will the first time after
a server reboot), but it will NOT close the connection at
the end of the request - instead, it will save it in a
connection pool so that a subsequent request can continue to
use the same connection. It's intended for pages that do
have a heavy usage - where the resources burn up by opening
and closing connections every time might have a severe
effect on performance. If your local supermarket had a door
that was opened each time someone went in and out, there
would be a lot of needless opening and closing going on -
better to leave it open and let a whole lot of people in and
out at the same time.
But mysql_pconnect does require some tuning of the servers
and you may need to limit the numbers of connections /
children and configure timeouts and how to deal with idle
children. The PHP website includes an overview of this to
get you started.
Finally, it is worth stressing what a persistant connect
does NOT give you. It does NOT give you sessions. It does
NOT give you a per-site-visitor login. It does NOT give you
any extra functioanllity. What it does give you - in the
right circumstances - is an efficiency improvement.

Admin May 17, 2020

mysql_pconnect() will maintain a persistent connection to
the database. whenever your script calls the connect to
database function, it first searches already existing
connections to the database and if exists it will use the
same connection to connect to the database, if not it will
open a new connection to the database. ie. Connection is
Persistent
where as mysql_connect() function will establish a new
connection whenever a connection to database needed, and
after executing the script, this function disconnects the
connection. ie. connection is not a persistent one.
mysql_pconnect() function is used where your site has a
Heavy Traffic and where as mysql_connect() function is used
when there is moderate/less traffic to your site.

Ques:- does PHP support foreign key and Rollback?yes or not.if not then why. how will you done these concept in php?
Asked In :-
Right Answer:
Yes, PHP supports foreign keys and rollback, but these features are not directly part of PHP itself; they are handled by the database management system (DBMS) that PHP interacts with, such as MySQL. To implement foreign keys and rollback in PHP, you would use SQL commands within a transaction. For example, you can use `BEGIN`, `COMMIT`, and `ROLLBACK` statements in your SQL queries to manage transactions and foreign key constraints in your database.
Comments
Admin May 17, 2020

PHP supports Foreign Keys in InnoDB Storage Engine in
version and above 4.0. It checks the foreign key referential
integrities on Delete and Select statements. If you strictly
needed the foreign keys and speed is not a concern then you
can create table structures using InnoDB Storage Engine.
Where as MyISAM Storage Engines does not allow foreign key
concept. But it will parse the table that contains foreign
keys but wont check the referential integreties. So it is
the job of the designer/programmer to check the desired key
and its dependency in multiple tables.
Let us suppose you have a field F1(primary)in Table1 and
this field is referenced in another tables denoted as (F2,
F3) in tables Table2, Table3......(as a foreign key)
and when you want to perform a DELETE operation/query based
on field F1, then
First you need to write a query to Delete the specified row
in Table1
and you also need to write a query to Delete all
dependent/referenced rows in other tables Table2, Table3...

Ques:- Why these language is needed?
Asked In :-
Right Answer:
PHP is needed for server-side scripting, allowing developers to create dynamic web pages, handle form data, manage sessions, and interact with databases efficiently.
Comments
Admin May 17, 2020

PHP is a cross platform, html embedded, server side, web
scripting language.
i.e. you can run it on different platform like windows,
unix, mac etc... and you can write php code in to the file
which embedded with html code and PHP is executed on server
side specially web server like apache, microsoft IIS, or
NetScap, etc...

Ques:- How do you run a php script from the command line?
Asked In :-
Right Answer:
You can run a PHP script from the command line by using the following command:

```bash
php path/to/your/script.php
```
Comments
Admin May 17, 2020

Answer :
you can execute thefrom anywhere like a command prompt.
in unix like OS you use the following:
/path/to/php -f /path/to/script.php
For windows OS's use the following
c:pathtophp.exe -f c:pathtoscript.php
and U can get the information by running the
C:pathtophp.exe -f

Ques:- when you will get the message/error “headers already sent”?
Asked In :-
Comments
Admin May 17, 2020

if u print any message on the browser using echo statement
or any html tags before using the "session_start()" like
statements in the scripts.
if u want to overcome that problem
simply write "ob_start();" at the very starting of script
and "ob_end_flush();" at the end.

Ques:- How can you get, the total size of a certain directory?
Asked In :-
Right Answer:
You can get the total size of a directory in PHP using the following code:

```php
function getDirectorySize($dir) {
$size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $file) {
$size += $file->getSize();
}
return $size;
}

$totalSize = getDirectorySize('/path/to/directory');
```
Comments
Admin May 17, 2020

You can use the folowing function as shown in alt.php by
ryanflynnn at my-deja.com:
<?php
$totalsize=0;
function show_dir($dir, $pos=2){
global $totalsize;
if($pos == 2)
echo "<hr><pre>";
$handle = @opendir($dir);
while ($file = @readdir ($handle)){
if (eregi("^.{1,2}$",$file))
continue;
if(is_dir($dir.$file)){
echo "|- ".$pos."s <b>$file</b>n";
show_dir("$dir.$file/", $pos+3);
}else{
$size=filesize($dir.$file);
echo "|- ".$pos."s $file ";
echo("$size <br>");
$totalsize=$totalsize+$size;
}
}
@closedir($handle);
if($pos == 2) echo "</pre><hr>";
return($totalsize);
}
$totalsize = show_dir("c:/winnt/system32/");
echo($totalsize);
?>

Ques:- How to find out, how a user visited a particular page?
Asked In :-
Right Answer:
You can find out how a user visited a particular page by checking the `$_SERVER['HTTP_REFERER']` variable in PHP, which contains the URL of the page that linked to the current page.
Comments
Admin May 17, 2020

Sorry for previous wrong answer.
In php u can get through $_SERVER page referer.

Ques:- Without using forms and hidden variables, how to send variables from a PHP script to another URL using POST method?
Asked In :-
Right Answer:
You can use the `cURL` library in PHP to send variables to another URL using the POST method. Here’s a simple example:

```php
$url = 'http://example.com/target.php';
$data = array('key1' => 'value1', 'key2' => 'value2');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
```
Ques:- How do you set the browser timeout?
Asked In :-
Right Answer:
In PHP, you cannot directly set the browser timeout. However, you can control the script execution time using `set_time_limit()` or by configuring the `max_execution_time` in `php.ini`. For client-side timeout, you would typically use JavaScript with `setTimeout()` or manage it through server-side headers.
Comments
Admin May 17, 2020

for($i = 2000; $i < 2011; $i++) {
echo "<br>".$i, ': ', (date('L', strtotime("$i-01-
01")) ? 'Yes' : 'No'), '<br/>';
}

Admin May 17, 2020

using the follwing function u can set the script timeout
set_time_limit(900);
timeout too 900 seconds or 15 minutes.



The Core PHP category on takluu.com is designed for developers preparing for interviews that test their understanding of PHP fundamentals and server-side scripting. Core PHP forms the backbone of many web applications, enabling developers to create dynamic, interactive, and database-driven websites.

This section covers important topics such as PHP syntax, variables, data types, control structures, functions, arrays, sessions, cookies, file handling, and error handling. Additionally, it delves into working with forms, connecting to databases using MySQLi or PDO, and implementing security best practices like input validation and SQL injection prevention.

Interview questions often include practical coding problems, debugging scenarios, and explanations of how PHP interacts with the web server and databases. Understanding how to write clean, maintainable code and optimize PHP scripts for performance is also emphasized.

Candidates aspiring for roles like PHP Developer, Backend Developer, or Full Stack Developer will benefit from detailed tutorials, common interview questions, and real-world examples focused on Core PHP concepts.

At Takluu, we focus on building a strong foundation in Core PHP, enabling you to handle coding rounds confidently and develop scalable web solutions.

Whether you are a beginner or looking to refresh your PHP skills, this category provides comprehensive learning material and interview preparation tips to help you succeed.

AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users