Find Interview Questions for Top Companies
Ques:- How to prevent form hijacking in PHP?
Asked In :-
Right Answer:
To prevent form hijacking in PHP, you can implement the following measures:

1. **Use CSRF Tokens**: Generate a unique token for each form submission and validate it on the server side.
2. **Validate Referrer Header**: Check the HTTP referrer header to ensure the request comes from your site.
3. **Use HTTPS**: Always use HTTPS to encrypt data transmitted between the client and server.
4. **Limit Form Submission**: Implement rate limiting to prevent automated submissions.
5. **Session Management**: Ensure proper session management and regenerate session IDs after login.

Implementing these techniques will help secure your forms against hijacking.
Ques:- What do you need to do to improve the performance (speedy execution) for the script you have written?
Asked In :-
Right Answer:
To improve the performance of a PHP script, you can:

1. Optimize algorithms and data structures.
2. Use caching mechanisms (e.g., opcode caching, data caching).
3. Minimize database queries and use efficient queries.
4. Use built-in PHP functions instead of custom code where possible.
5. Reduce file I/O operations.
6. Enable output buffering.
7. Profile the script to identify bottlenecks.
8. Avoid unnecessary computations and loops.
9. Use asynchronous processing for long-running tasks.
10. Keep the code clean and maintainable for easier optimization.
Ques:- How to add multiple categories through PHP?
Asked In :-
Right Answer:
To add multiple categories through PHP, you can use an array to hold the category names and then loop through that array to insert each category into the database. Here’s a simple example:

```php
$categories = ['Category1', 'Category2', 'Category3']; // Array of categories

foreach ($categories as $category) {
$stmt = $pdo->prepare("INSERT INTO categories (name) VALUES (:name)");
$stmt->execute(['name' => $category]);
}
```

Make sure to replace `$pdo` with your actual database connection variable.
Ques:- What are new features that are in added in PHP5?
Asked In :-
Right Answer:
PHP5 introduced several new features, including:

1. **Object-Oriented Programming (OOP)**: Improved support for OOP with features like visibility (public, private, protected), interfaces, and abstract classes.
2. **PDO (PHP Data Objects)**: A consistent interface for accessing databases.
3. **XML Support**: Enhanced XML handling with the SimpleXML and DOM extensions.
4. **Error Handling**: Introduction of exceptions for better error management.
5. **Type Hinting**: Ability to specify expected data types for function arguments.
6. **Improved MySQL Support**: MySQLi extension for improved database interactions.
7. **SOAP Support**: Built-in support for SOAP web services.
8. **Reflection API**: Ability to introspect classes, interfaces, functions, and methods.
9. **New Standard Library (SPL)**: A set of interfaces and classes for common data structures and algorithms.
Ques:- How to handle drop down box change event without refreshing page?
Asked In :-
Right Answer:
You can handle a dropdown box change event without refreshing the page by using JavaScript or jQuery to listen for the change event and then making an AJAX request to update the content dynamically. Here's a simple example using jQuery:

```html
<select id="myDropdown">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>

<div id="result"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$('#myDropdown').change(function() {
var selectedValue = $(this).val();
$.ajax({
url: 'your-server-side-script.php',
type: 'POST',
data: { value: selectedValue },
success: function(response) {
$('#result').html(response);
}
});
});
</script>
```

Replace `'your-server-side-script.php'` with the path
Ques:- How do you capture audio/video in PHP?
Asked In :-
Right Answer:
PHP itself does not have built-in capabilities to capture audio or video directly from a user's device. To capture audio or video, you typically use HTML5 and JavaScript (e.g., the MediaRecorder API) in the frontend to record media, and then send the recorded files to a PHP backend for processing or storage via an HTTP request.
Ques:- What is the use of a form in html page? Is there any way to submit the page without using the form.
Asked In :- Botree Software,
Right Answer:
A form in an HTML page is used to collect user input and submit it to a server for processing. Yes, you can submit a page without using a form by using JavaScript to send data via AJAX or by using the `fetch` API to make HTTP requests.
Ques:- How many ways I can redirect a PHP page?
Asked In :- ACC Cement,
Right Answer:
You can redirect a PHP page in the following ways:

1. Using the `header()` function.
2. Using HTML meta refresh tag.
3. Using JavaScript `window.location` method.
4. Using HTTP response status codes (like 301 or 302) with `header()`.
Ques:- How do I add to the beginning of an array and find the number of elements in it?
Asked In :-
Right Answer:
To add to the beginning of an array in PHP, use the `array_unshift()` function. To find the number of elements in the array, use the `count()` function.

Example:
```php
$array = [2, 3, 4];
array_unshift($array, 1); // Adds 1 to the beginning
$numberOfElements = count($array); // Gets the number of elements
```
Ques:- What is the functionality of md5 function in PHP?
Asked In :-
Right Answer:
The `md5` function in PHP generates a 32-character hexadecimal hash from a given string, which is commonly used for data integrity checks and storing passwords securely.
Ques:- Where are the sessions storing ?
Asked In :-
Right Answer:
Sessions in PHP are typically stored on the server's filesystem by default, in temporary files. However, they can also be stored in other locations like databases or memory (using tools like Redis or Memcached) if configured accordingly.
Ques:- What is the difference between PHP,ASP and JSP?
Asked In :- trident group india,
Right Answer:
PHP is a server-side scripting language primarily used for web development, ASP (Active Server Pages) is a Microsoft technology for building dynamic web pages, and JSP (JavaServer Pages) is a Java-based technology that allows for the creation of dynamic web content. PHP is open-source and platform-independent, ASP is Windows-based, and JSP runs on any server that supports Java.
Ques:- Can anyone explain oops concept in php or give website tolearn this concept clearly?
Asked In :-
Right Answer:
Object-Oriented Programming (OOP) in PHP is a programming paradigm that uses "objects" to represent data and methods. The main concepts of OOP in PHP include:

1. **Classes**: Blueprints for creating objects.
2. **Objects**: Instances of classes.
3. **Inheritance**: Mechanism to create a new class from an existing class.
4. **Encapsulation**: Restricting access to certain components of an object.
5. **Polymorphism**: Ability to present the same interface for different data types.

For learning OOP in PHP, you can visit websites like:
- [PHP.net](https://www.php.net/manual/en/language.oop5.php)
- [W3Schools](https://www.w3schools.com/php/php_oop.asp)
- [Tutorialspoint](https://www.tutorialspoint.com/php/php_object_oriented.htm)
Ques:- How to send mail in php but mail should be send in inbox not in spam…..:(
Asked In :- Miller & Carter, isme,
Right Answer:
To send mail in PHP that is less likely to go to spam, follow these best practices:

1. **Use a Valid Email Address**: Use a legitimate "From" email address that matches your domain.
2. **Set Proper Headers**: Include headers like `From`, `Reply-To`, and `Content-Type`.
3. **Use SMTP**: Use an SMTP server for sending emails instead of the `mail()` function. Libraries like PHPMailer or SwiftMailer can help.
4. **Authenticate Your Domain**: Set up SPF, DKIM, and DMARC records for your domain to improve deliverability.
5. **Avoid Spammy Content**: Keep the email content professional and avoid excessive links, images, or spammy keywords.
6. **Test Before Sending**: Use tools to test your emails for spam score before sending.

Example using PHPMailer:

```php
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

require 'vendor/aut
Ques:- What is hidden variable? what is its difference with thenormal variable…
Asked In :- Airborne Recruiting, Karomi,
Right Answer:
A hidden variable, often referred to as a hidden field in web development, is a variable that is not visible to the user but is sent to the server when a form is submitted. It is used to store data that should not be altered by the user, such as session IDs or tokens. The difference between a hidden variable and a normal variable is that a normal variable can be seen and modified by the user, while a hidden variable is not displayed in the user interface and is intended to be kept secure and unchanged by the user.
Ques:- WHat is the diff. between PHP4 and PHP5?
Asked In :- Leeway Hertz,
Right Answer:
PHP4 and PHP5 differ primarily in the following ways:

1. **Object-Oriented Programming**: PHP5 introduced a more robust object-oriented programming model, including support for visibility (public, private, protected), interfaces, and abstract classes, while PHP4 had a limited OOP model.

2. **Improved MySQL Support**: PHP5 includes the MySQLi extension, which provides a better interface for interacting with MySQL databases, whereas PHP4 used the older MySQL extension.

3. **Error Handling**: PHP5 introduced exceptions for error handling, allowing for more structured error management, while PHP4 relied on traditional error handling methods.

4. **XML Support**: PHP5 has enhanced XML support with the SimpleXML and DOM extensions, making it easier to work with XML data compared to PHP4.

5. **SOAP Support**: PHP5 includes built-in support for SOAP (Simple Object Access Protocol), facilitating web services, which was not available in PHP4.

6
Ques:- Under what circumstances would you use sort(), assort() and ksort?
Asked In :- bridgewater associates,
Right Answer:
- **sort()**: Use when you want to sort an array in ascending order by values, regardless of keys.
- **asort()**: Use when you want to sort an associative array in ascending order by values while maintaining key-value associations.
- **ksort()**: Use when you want to sort an associative array in ascending order by keys while maintaining key-value associations.
Ques:- How can I embed a java programme in PHP file and what changes have to be done in PHP.ini file?
Asked In :- unite students,
Right Answer:
To embed a Java program in a PHP file, you can use the `exec()` or `shell_exec()` functions in PHP to call the Java program from the command line. Ensure that the Java Runtime Environment (JRE) is installed on the server.

In the `php.ini` file, you may need to adjust the `disable_functions` directive to ensure that `exec()` or `shell_exec()` is not disabled. Additionally, ensure that the `safe_mode` is off, as it can restrict the execution of external programs.

Example PHP code to execute a Java program:
```php
$output = shell_exec('java -cp /path/to/your/classes YourJavaClass');
echo $output;
```
Ques:- If the server is loaded with too manysession files there is a possibility of server crash. Howcan we solve this issue?
Right Answer:
To solve the issue of too many session files causing server crashes, you can implement the following strategies:

1. **Use Database for Sessions**: Store session data in a database instead of files to manage sessions more efficiently.
2. **Session Garbage Collection**: Configure PHP's session garbage collection settings to automatically clean up old session files.
3. **Increase Session Lifetime**: Adjust the session lifetime to reduce the number of active sessions.
4. **Use Memory-Based Storage**: Utilize memory-based session storage solutions like Redis or Memcached for faster access and reduced file usage.
5. **Limit Session Creation**: Implement logic to limit the number of sessions per user or IP address.
Ques:- How we connect with the version?
Asked In :-
Right Answer:
To connect with a specific version in PHP, you can use version control systems like Git. You can clone a repository and check out a specific version or tag using the command `git checkout <version-tag>`. If you're referring to connecting to a specific PHP version on a server, you can configure your web server (like Apache or Nginx) to use the desired PHP version through settings or by using tools like PHP-FPM.


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