0% found this document useful (0 votes)
12 views14 pages

Viva Questions For Web Development Using PHP

The document provides a comprehensive list of important viva questions for Web Development using PHP, covering topics such as PHP basics, data types, control structures, functions, sessions, cookies, database connectivity, security, and object-oriented programming. It also includes real-world scenario questions and best practices for PHP development. Additionally, there are instructions for generating a PDF containing these questions using Python's FPDF library.

Uploaded by

Sai Nithesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views14 pages

Viva Questions For Web Development Using PHP

The document provides a comprehensive list of important viva questions for Web Development using PHP, covering topics such as PHP basics, data types, control structures, functions, sessions, cookies, database connectivity, security, and object-oriented programming. It also includes real-world scenario questions and best practices for PHP development. Additionally, there are instructions for generating a PDF containing these questions using Python's FPDF library.

Uploaded by

Sai Nithesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Sure!

Here are more important viva questions for Web Development using PHP, including some
advanced and real-world topics, as well as questions on best practices:

Basics of PHP

1. What is PHP?

o PHP (Hypertext Preprocessor) is a server-side scripting language used to develop


dynamic web pages.

2. How is PHP different from client-side scripting languages like JavaScript?

o PHP runs on the server, while JavaScript runs in the browser (client side).

3. What are the main features of PHP?

o Open-source, platform-independent, easy to learn, supports databases, and


integrates with HTML.

4. How do you write a simple PHP script?

php

CopyEdit

<?php

echo "Hello, World!";

?>

5. What are variables in PHP? How are they declared?

o Variables start with a $ sign. Example: $name = "John";

🔹 Data Types and Operators

6. What are the different data types in PHP?

o String, Integer, Float, Boolean, Array, Object, NULL, Resource.

7. What is the difference between == and === in PHP?

o == compares values, === compares both value and data type.

8. What are PHP’s logical operators?

o && (AND), || (OR), ! (NOT).

🔹 Control Structures

9. Explain the if...else structure in PHP.

php

CopyEdit
if ($a > $b) {

echo "a is greater";

} else {

echo "b is greater";

10. What is the use of switch in PHP?

o Used for multi-way decision making.

🔹 Functions

11. How do you define a function in PHP?

php

CopyEdit

function greet($name) {

return "Hello, $name!";

12. What is the difference between include and require?

o include gives a warning if the file is missing, while require gives a fatal error.

🔹 Forms and User Input

13. How do you collect data from an HTML form using PHP?

o Using $_GET or $_POST.

14. What is the difference between $_GET and $_POST?

o $_GET shows data in URL, $_POST does not.

15. How do you validate form inputs in PHP?

o Using functions like isset(), empty(), filter_var().

🔹 Sessions and Cookies

16. What is a session in PHP?

o A way to store user information across multiple pages.

17. How do you start a session in PHP?


php

CopyEdit

session_start();

18. What is a cookie in PHP?

o A small file stored on the client’s machine.

19. Difference between session and cookie?

o Session data is stored on the server; cookies are stored on the client.

🔹 Database Connectivity (MySQL)

20. How do you connect PHP to a MySQL database?

php

CopyEdit

$conn = mysqli_connect("localhost", "username", "password", "database");

21. How do you execute a SELECT query in PHP?

php

CopyEdit

$result = mysqli_query($conn, "SELECT * FROM users");

22. How do you fetch results from a query?

php

CopyEdit

while ($row = mysqli_fetch_assoc($result)) {

echo $row['name'];

🔹 Security

23. How to prevent SQL Injection in PHP?

o Use prepared statements with mysqli or PDO.

24. What is XSS and how to prevent it?

o Cross-site scripting; prevented using htmlspecialchars().

25. What is PDO in PHP?

o PHP Data Object; a database access layer that supports multiple DBs.
26. What are some common frameworks for PHP?

o Laravel, CodeIgniter, Symfony, Yii.

27. What is AJAX and how is it used with PHP?

o AJAX allows asynchronous communication with the server without reloading the
page.

🔹 Object-Oriented PHP (OOP)

28. What is Object-Oriented Programming in PHP?

 It is a programming paradigm based on objects and classes, which helps in modular and
reusable code.

29. How do you define a class and object in PHP?

php

CopyEdit

class Car {

public $color;

function setColor($c) {

$this->color = $c;

$obj = new Car();

30. What is the use of $this keyword in PHP?

 Refers to the current object in a class.

31. What are the visibility types in PHP?

 public, private, and protected.

32. What is inheritance in PHP?

 A class can inherit properties and methods from another class using extends.

🔹 File Handling in PHP

33. How do you read a file in PHP?

php

CopyEdit

$file = fopen("file.txt", "r");

echo fread($file, filesize("file.txt"));


fclose($file);

34. How do you write to a file in PHP?

php

CopyEdit

$file = fopen("file.txt", "w");

fwrite($file, "Hello World!");

fclose($file);

35. What is file_get_contents() used for?

 Reads an entire file into a string.

🔹 Error Handling

36. What are the error types in PHP?

 Notices, Warnings, Fatal Errors, Parse Errors.

37. How do you handle errors in PHP?

 Using try...catch, error_reporting(), or set_error_handler().

38. What is the difference between die() and exit()?

 Both stop the execution of a script. They are functionally identical.

🔹 Date and Time Functions

39. How do you get the current date and time in PHP?

php

CopyEdit

echo date("Y-m-d H:i:s");

40. How do you add 7 days to the current date in PHP?

php

CopyEdit

echo date('Y-m-d', strtotime("+7 days"));

🔹 PHP and HTML Integration

41. Can PHP be embedded in HTML?

 Yes, PHP code is embedded within <?php ... ?> tags inside an HTML document.
42. How do you pass variables from PHP to JavaScript?

php

CopyEdit

<script>

var jsVar = "<?php echo $phpVar; ?>";

</script>

🔹 Email and File Upload

43. How do you send an email using PHP?

php

CopyEdit

mail("[email protected]", "Subject", "Message");

44. How do you upload a file in PHP?

 Use a form with enctype="multipart/form-data" and process it using $_FILES.

45. How do you validate uploaded files (type, size)?

 Use $_FILES['file']['type'], $_FILES['file']['size'], and pathinfo().

🔹 PHP Configuration and Deployment

46. What is php.ini?

 PHP's main configuration file.

47. How can you increase PHP script execution time?

 Modify max_execution_time in php.ini or use set_time_limit().

48. What is composer in PHP?

 A dependency manager for PHP.

49. What is .htaccess and how is it used in PHP projects?

 A configuration file for Apache web server to control URL routing, redirects, and security
settings.

🔹 Security Best Practices

50. How do you sanitize user input in PHP?

 Use filter_input(), htmlspecialchars(), or mysqli_real_escape_string().


51. What are CSRF and how can you prevent it in PHP forms?

 Cross-site Request Forgery; use CSRF tokens in forms.

52. What is the use of password_hash() and password_verify()?

 For securely storing and verifying hashed passwords.

🔹 Miscellaneous

53. What are superglobals in PHP?

 Built-in variables accessible anywhere: $_POST, $_GET, $_SESSION, $_COOKIE, $_FILES, etc.

54. What is the difference between isset() and empty()?

 isset() checks if a variable is set and not null; empty() checks if a variable has an empty value.

55. What is output buffering in PHP?

 Using ob_start() and ob_end_flush() to control when output is sent to the browser.

✅ Bonus: Real-world Scenario Questions

56. How would you create a login system using PHP and MySQL? (Expect to explain session
usage, hashing, form handling, etc.)

57. How do you implement pagination in PHP?

58. What would you do to speed up a slow PHP website?

 Use caching, optimize DB queries, reduce file size, use PHP accelerators.

59. How do you debug PHP code?

 Use var_dump(), print_r(), logging, or tools like Xdebug.

60. How do you handle multiple file uploads in PHP?

✅ Steps to Run:

1. Install the required package:

bash

CopyEdit

pip install fpdf

2. Copy and paste this code into a Python script (e.g., php_viva_notes.py):

python

CopyEdit
from fpdf import FPDF

class PDF(FPDF):

def header(self):

self.set_font("Arial", "B", 14)

self.cell(0, 10, "Web Development Using PHP - Viva Questions", ln=True, align="C")

self.ln(10)

def chapter_title(self, title):

self.set_font("Arial", "B", 12)

self.set_text_color(30, 30, 120)

self.cell(0, 10, title, ln=True)

self.set_text_color(0, 0, 0)

def chapter_body(self, body):

self.set_font("Arial", "", 11)

self.multi_cell(0, 8, body)

self.ln()

def add_question_set(self, title, questions):

self.add_page()

self.chapter_title(title)

for q in questions:

self.chapter_body(q)

questions = {

"Basics of PHP": [

"1. What is PHP? - PHP stands for Hypertext Preprocessor, a server-side scripting language for
web development.",

"2. Difference between PHP and JavaScript? - PHP is server-side; JavaScript is client-side.",

"3. Features of PHP? - Open-source, database support, platform-independent, easy integration


with HTML.",
],

"Data Types and Operators": [

"4. Data types in PHP? - String, Integer, Float, Boolean, Array, Object, NULL.",

"5. Difference between == and ===? - == compares value; === compares value and type.",

],

"Control Structures": [

"6. Example of if...else in PHP.",

"7. Use of switch statement in PHP.",

],

"Functions": [

"8. Defining a function in PHP.",

"9. Difference between include and require.",

],

"Forms and User Input": [

"10. Collecting data using $_GET and $_POST.",

"11. Difference between $_GET and $_POST.",

"12. Input validation using isset(), empty(), filter_var().",

],

"Sessions and Cookies": [

"13. What is a session? How to start a session?",

"14. What is a cookie? Difference between session and cookie?",

],

"Database Connectivity": [

"15. Connecting PHP to MySQL using mysqli_connect().",

"16. Executing SELECT queries and fetching data.",

],

"Security": [

"17. Preventing SQL Injection - Use prepared statements.",

"18. Preventing XSS - Use htmlspecialchars().",

],

"OOP in PHP": [
"19. What is OOP? - Programming with classes and objects.",

"20. Defining a class and object in PHP.",

"21. Visibility types - public, private, protected.",

],

"File Handling": [

"22. Reading and writing files using fopen(), fread(), fwrite(), fclose().",

"23. file_get_contents() - reads entire file into a string.",

],

"Error Handling": [

"24. Error types: Notice, Warning, Fatal, Parse.",

"25. Handling errors using try...catch and set_error_handler().",

],

"Email and File Upload": [

"26. Sending email with mail().",

"27. File upload using $_FILES and validation.",

],

"Miscellaneous": [

"28. Superglobals: $_POST, $_GET, $_SESSION, $_COOKIE, etc.",

"29. Difference between isset() and empty().",

"30. Output buffering using ob_start(), ob_end_flush().",

],

"Real-world Scenario": [

"31. Creating a login system using PHP and MySQL.",

"32. Pagination in PHP.",

"33. Optimizing performance: caching, query optimization, compression.",

"34. Debugging using var_dump(), print_r(), or Xdebug.",

pdf = PDF()

pdf.set_auto_page_break(auto=True, margin=15)
for title, q_list in questions.items():

pdf.add_question_set(title, q_list)

pdf.output("PHP_Viva_Questions_Notes.pdf")

🔹 Object-Oriented PHP (OOP)

28. What is Object-Oriented Programming in PHP?

 It is a programming paradigm based on objects and classes, which helps in modular and
reusable code.

29. How do you define a class and object in PHP?

class Car {

public $color;

function setColor($c) {

$this->color = $c;

$obj = new Car();

30. What is the use of $this keyword in PHP?

 Refers to the current object in a class.

31. What are the visibility types in PHP?

 public, private, and protected.

32. What is inheritance in PHP?

 A class can inherit properties and methods from another class using extends.

🔹 File Handling in PHP

33. How do you read a file in PHP?

$file = fopen("file.txt", "r");

echo fread($file, filesize("file.txt"));

fclose($file);

34. How do you write to a file in PHP?


$file = fopen("file.txt", "w");

fwrite($file, "Hello World!");

fclose($file);

35. What is file_get_contents() used for?

 Reads an entire file into a string.

🔹 Error Handling

36. What are the error types in PHP?

 Notices, Warnings, Fatal Errors, Parse Errors.

37. How do you handle errors in PHP?

 Using try...catch, error_reporting(), or set_error_handler().

38. What is the difference between die() and exit()?

 Both stop the execution of a script. They are functionally identical.

🔹 Date and Time Functions

39. How do you get the current date and time in PHP?

echo date("Y-m-d H:i:s");

40. How do you add 7 days to the current date in PHP?

echo date('Y-m-d', strtotime("+7 days"));

🔹 PHP and HTML Integration

41. Can PHP be embedded in HTML?

 Yes, PHP code is embedded within <?php ... ?> tags inside an HTML document.

42. How do you pass variables from PHP to JavaScript?

<script>

var jsVar = "<?php echo $phpVar; ?>";

</script>

🔹 Email and File Upload

43. How do you send an email using PHP?

mail("[email protected]", "Subject", "Message");


44. How do you upload a file in PHP?

 Use a form with enctype="multipart/form-data" and process it using $_FILES.

45. How do you validate uploaded files (type, size)?

 Use $_FILES['file']['type'], $_FILES['file']['size'], and pathinfo().

🔹 PHP Configuration and Deployment

46. What is php.ini?

 PHP's main configuration file.

47. How can you increase PHP script execution time?

 Modify max_execution_time in php.ini or use set_time_limit().

48. What is composer in PHP?

 A dependency manager for PHP.

49. What is .htaccess and how is it used in PHP projects?

 A configuration file for Apache web server to control URL routing, redirects, and security
settings.

🔹 Security Best Practices

50. How do you sanitize user input in PHP?

 Use filter_input(), htmlspecialchars(), or mysqli_real_escape_string().

51. What are CSRF and how can you prevent it in PHP forms?

 Cross-site Request Forgery; use CSRF tokens in forms.

52. What is the use of password_hash() and password_verify()?

 For securely storing and verifying hashed passwords.

🔹 Miscellaneous

53. What are superglobals in PHP?

 Built-in variables accessible anywhere: $_POST, $_GET, $_SESSION, $_COOKIE, $_FILES, etc.

54. What is the difference between isset() and empty()?

 isset() checks if a variable is set and not null; empty() checks if a variable has an empty value.

55. What is output buffering in PHP?


 Using ob_start() and ob_end_flush() to control when output is sent to the browser.

✅ Bonus: Real-world Scenario Questions

56. How would you create a login system using PHP and MySQL? (Expect to explain session
usage, hashing, form handling, etc.)

57. How do you implement pagination in PHP?

58. What would you do to speed up a slow PHP website?

 Use caching, optimize DB queries, reduce file size, use PHP accelerators.

59. How do you debug PHP code?

 Use var_dump(), print_r(), logging, or tools like Xdebug.

60. How do you handle multiple file uploads in PHP?

You might also like