PHP Interview Questions and Answers For Experienced
How to collect IP address from an HTTP request ?
$_SERVER[‘REMOTE_ADDR’]; How to collect IP address of the Web server in php ?
$_SERVER[‘SERVER_ADDR’]; How to enable error reporting ?
error_reporting(E_ALL);
What is $_GLOBAL ?
It is an associative array which containing references to all variables currently defined in the global scope of the script. What is .htaccess file ?
.htaccess is a configuration file used to alter the default behavior of a Apache web server software. Most common usage is to redirect the http request to some URLs based on some conditions. For example, we can hide the .html or .php extensions of the URLs to make it SEO friendly. How to print structured information about a available in PHP ?
var_dump — This function displays structured information about one or more expressions that includes its value and type. Objects and arrays are explored recursively with values indented to show structure. Usage var_dump($a); What is the difference between var_dump and print_r ?
var_dump will display all the information of a variable including keys values and types while print_r display the keys and values only in a human readable format. What is automatic type conversion ?
In php we can declare variables without specifying its type, php it do that process automatically since PHP is a loosely types language. For example : How to make API calls from php scripts ?
We can use cURL library to make HTTP calls from a php script$ch = curl_init(); $postData=’var1=value1&var2=value2&var3=value3′; curl_setopt($ch, CURLOPT_URL, “http://mydomain.com/ajaxurl”); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); echo $result;die;
How to change the php configurations at run time ?
We can use ini_set
function to change the configurations of php at run time.