Basics PHP Questions & Answer
The location of the $_SESSION variable storage is determined by PHP's session.save_path configuration. Usually this is /tmp on a Linux/Unix system. Use the phpinfo() function to view your particular settings if not 100% sure by creating a file with this content in the DocumentRoot of your domain.
A Content Management System (CMS) is a collection of procedures used to manage work flow in a collaborative environment.
Here are four basics type of run time error in php.
1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.
2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place.
4. Parse Error: When we make mistake in PHP code like, missing semicolon or any unexpected symbol in code.
There is slight difference between echo and print. But both are used to print line of code to the browser.
There are two main difference between echo and print:-
- echo does not return any value while print returns true or false on successful print.
- echo is faster than print.
- print can be used in expressions, where echo cannot.
ECHO :
- Language constuct and behaves like statement. It won't return value.
- echo takes multiple parameter seperated by commas.
- Faster than print.
PRINT:
- Language construct and behaves like function. It return true / false.
- print is part of precedence table.
- print take only one parameter.
- Echo works faster than print().
- Echo and print are language construct.
- Print behaves as a function and it returns an integer value.
- Echo does not returns any values.
- Echo is not suitable for conditional construct
- Print is suitable for conditional construct.
- Print process is slower than echo
REQUIRE()
- The file should exist.Otherwise it will produce an Fatal error.the program cannot continue.
- Can call same file more than once.
REQUIRE_ONCE()
- Missing file throws Fatal Error and stops script.
- Cannot call same file more than once.
INCLUDE()
- Missing file throws Warning and keeps going.
- Can call same file more than once.
- The file is not mandatory.
- The program will run even if there is no such a file producing a warning.
INCLUDE_ONCE()
- Missing file throws Warning and keeps going.
- Cannot call same file more than once.
There are several differences between PHP4 and PHP5:
- Unified constructor and Destructor.
- Exception has been introduced.
- New error level named E_STRICT has been introduced.
- Now we can define full method definitions for a abstract class.
- Within a class we can define class constants.
- We can use the final keyword to indicate that a method cannot be overridden by a child.
- Public, private and protected method introduced.
- Magic methods has been included.
- We can pass value by reference
- PHP4 uses Zend engine 1.0 as a parser.PHP5 uses Zend engine 2.0
The simplest way to get the client’s IP address is using the $_SERVER['REMOTE_ADDR'] or $_SERVER['REMOTE_HOST'] variables. However, sometimes this does not return the correct IP address of the client, so we can use some other server variables to get the IP address.
unset() is a function for variable management. It will make a variable undefined. Or we can say that unset() is used to null out the value of a given variable. OR Unset() is used to destroy a variable in PHP. In can be used to remove a single variable, multiple variables, or an element from an array.
unlink() is a function for file system handling, unlink() is used to delete files. Suppose you have uploaded a file and wants to delete this file through the coding then unlink() function is used to delete the file.
The GET method
- It sends encoded user information append to the page request.
- The GET method produces a long string that appears in your server logs, in the browser's Location: box.
- The GET method is restricted to send upto 1024 characters only.
- Never use GET method if you have password or other sensitive information to be sent to the server.
- GET can't be used to send binary data, like images or word documents, to the server.
- The data sent by GET method can be accessed using QUERY_STRING environment variable.
- The PHP provides $_GET associative array to access all the sent information using GET method.
The POST Method
- The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING.
- The POST method does not have any restriction on data size to be sent.
- The POST method can be used to send ASCII as well as binary data.
- The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.
- The PHP provides $_POST associative array to access all the sent information using POST method.
For enable error reporting in PHP need to enable error display (display_errors & error_reporting) in the php.ini. By default these are turned off. If unable to modify php.ini then set in .htaccess file:
Hot Questions
How to Get the Size of all Tables in a database in MySQL?