0% found this document useful (0 votes)
0 views

Web_Based_PHP_22619_Important_QA

The document provides important questions and answers regarding PHP, covering its features, differences between GET and POST methods, data types, session management, and file handling. It includes code snippets for practical examples, such as checking if a number is even or odd and reversing a string. Additionally, it explains PHP superglobals, error handling, and the use of the header function for redirection.

Uploaded by

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

Web_Based_PHP_22619_Important_QA

The document provides important questions and answers regarding PHP, covering its features, differences between GET and POST methods, data types, session management, and file handling. It includes code snippets for practical examples, such as checking if a number is even or odd and reversing a string. Additionally, it explains PHP superglobals, error handling, and the use of the header function for redirection.

Uploaded by

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

Web-Based PHP (22619) - Important Questions and Answers

1. What is PHP? Explain its features.

PHP (Hypertext Preprocessor) is a server-side scripting language used for web development.

Features:

- Open source

- Server-side execution

- Supports various databases (MySQL, PostgreSQL)

- Easy to integrate with HTML

- Platform independent

2. Difference between GET and POST methods in PHP.

GET: Sends data via URL, limited length, less secure.

POST: Sends data in request body, more secure, no size limit.

3. What is the use of isset() and empty() functions in PHP?

- isset(): Checks if variable is set and not NULL.

- empty(): Checks if variable is empty.

4. Explain PHP data types.

- String, Integer, Float, Boolean, Array, Object, NULL, Resource

5. Write a PHP script to check whether a number is even or odd.

$num = 10;

if ($num % 2 == 0) { echo "Even"; } else { echo "Odd"; }

6. What is a session? How is it different from a cookie?


Session stores data on server; cookies store data on client.

7. How to connect PHP to MySQL?

mysqli_connect("localhost", "username", "password", "database");

8. Types of loops in PHP:

for, while, do...while, foreach

9. Explain form handling.

<form method="post">

<input name="name">

</form>

echo $_POST['name'];

10. Difference between include and require.

- include: Warning if file not found, script continues.

- require: Fatal error if file not found, script stops.

11. What is an array? Types?

- Indexed, Associative, Multidimensional

12. Script to reverse a string:

strrev("Hello");

13. Difference between echo and print.

echo: No return, faster. print: Returns 1.


14. PHP Superglobals:

$_GET, $_POST, $_SESSION, $_COOKIE, $_FILES, $_SERVER, etc.

15. Display current date and time:

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

16. Create and destroy session:

session_start(); $_SESSION["user"]="admin"; session_destroy();

17. explode() vs implode():

explode(",", "a,b") => ["a","b"]

implode("-", ["a","b"]) => "a-b"

18. File upload:

<form enctype="multipart/form-data"><input type="file"></form>

move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/");

19. Error handling:

Functions: error_reporting(), try-catch, set_error_handler()

20. header() function:

header("Location: page.php"); // redirect

You might also like