What are the differences between GET and POST methods in form submitting?

Server side difference-

  • If the form is submitted by get method the data stored in $_GET Array.
  • If the form is submitted by post method the data stored in $_POST Array.

Browser side difference-

  • The data submitted by the GET method will display in the browser's address bar.
  • The Data submitted by the POST method will not be displayed anywhere on the browser.

Security basis difference -

  • GET method is generally used for submitting a small amount and less sensitive data.
  • POST method is generally used for submitting a large amount or sensitive data.

How can we submit from without a submit button?

We can submit the html form by using document.form.submit() function.

What are the differences between require, include and include_once?

include vs include_once : if we include file using include_once() file get included in only once but in case of include() get included every time.

include vs require : if include() will not able to find a specified file on location it will throw a warning but code will run .But in case of require() will throw a fatal error and script will not execute.

require vs require_once : In case of require_once() if the file has been already included then it will not be included again but require() will include file number of times you call require function.


What’s the difference between unset() and unlink()?

unset() sets a variable to undefined but unlink() deletes a file from the file system for given path.

How many types of error in PHP?

The following are the error type in PHP:

  • Notices – Notices are not critical errors, script execution does not stop. for example- undefined variable.
  • Warnings –It is important errors than notices but the scripts continue the execution.
  • Fatal Error – It causes the termination of the script execution when it occurs. For example calling a non-existent function.

How can you enable error reporting in PHP?

Enable error reporting in PHP by two ways-

  1. Set display_errors = on in php.ini (configuration file) file.
  2. Use ini_set function in php script and enable error reporting on by error_reporting function. For example-

ini_set('display_errors', 1)
error_reporting(E_ALL)
?>

What are the __construct() and __destruct() methods in a PHP class?

The constructor method is called during creation of object of a class, it is used to initialize the class properties. The destructor method will be called as soon as there are no other references to a particular object , destructor method is used to deallocate object and resources.

What is PHP?

PHP stand for Hypertext Preprocessor . It is a open source, general-purpose, server side scripting language that is most suited for web development and can be easily embedded into HTML. PHP is developed by Rasmus Lerdorf in the year 1994. Read PHP tutorial


What is the difference between Session and Cookie?

Difference between Session and Cookie-

  1. A cookie is stored by the browser and sent to the server with every request but session is a collection of data stored on the server and associated with a given user.
  2. Sessions are more secure because it is stored in server. Cookie can be turned off from browser and less secure.
  3. Data stored in cookie can be stored for longer period of time(months,years), depending on the life span of the cookie. But session data get lost when the web browser is closed.

What is the use of final keyword?

If the final keyword used with method ,it prevents child classes from overriding that method . If the class is defined as final then it cannot be extended.

What are interfaces in PHP?

Interfaces can have public methods not variables. The class that inherit that interface will have to implements all the methods. Interfaces are skeletons of methods which are implemented by developers.

What is preg_match() function in PHP?

preg_match() is a pattern matching built in function in PHP that works on string. It return true if pattern matched otherwise false if pattern not matched.

What is the purpose of $_PHP_SELF variable in PHP?

$_PHP_SELF − It returns current (executing) PHP file name and path (root path) of file.

How will you destroy the session?

A PHP session can be destroyed by session_destroy() function.

How will you redirect a page using PHP?

The PHP header() function supplies raw HTTP headers to the browser and used to redirect it to another location or page. The redirect script should be at the top of the page to prevent any other part of the page from loading.

function redirect($url) {
    ob_start();
    header('Location: '.$url);
    ob_end_flush();
    die();
}

What is the purpose of _LINE_ constant?

_LINE_ − The current line number of the file.


What is the purpose of _FILE_ constant?

_FILE_ is a magic constant that gives the filesystem path to the current .php file


What is the purpose of _FUNCTION_ constant?

_FUNCTION_ − The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.


What is the purpose of _CLASS_ constant?

_CLASS_ − The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.


What is the purpose of _METHOD_ constant?

_METHOD_ − The class method name.


Back to Top