Category Archives: PHP

how to get the server details in php

$_SERVER Data

$_SERVER is a super global array that containing information such as headers, paths, and script locations etc.
php server details
By using the $_SERVER  array you can get many server information like Server IP, Document root, Server name, server software and more.  The sever super global array are created by the server varies from server to server.

 

Here is all server element


 HTTP_HOST
 HTTP_CONNECTION
 HTTP_CACHE_CONTROL
 HTTP_ACCEPT
 HTTP_UPGRADE_INSECURE_REQUESTS
 HTTP_USER_AGENT
 HTTP_DNT
 HTTP_REFERER
 HTTP_ACCEPT_ENCODING
 HTTP_ACCEPT_LANGUAGE
 HTTP_COOKIE
 PATH
 SystemRoot
 COMSPEC
 PATHEXT
 WINDIR
 SERVER_SIGNATURE
 SERVER_SOFTWARE
 SERVER_NAME
 SERVER_ADDR
 SERVER_PORT
 REMOTE_ADDR
 DOCUMENT_ROOT
 REQUEST_SCHEME
 CONTEXT_PREFIX
 CONTEXT_DOCUMENT_ROOT
 SERVER_ADMIN
 SCRIPT_FILENAME
 REMOTE_PORT
 GATEWAY_INTERFACE
 SERVER_PROTOCOL
 REQUEST_METHOD
 QUERY_STRING
 REQUEST_URI
 SCRIPT_NAME
 PHP_SELF
 REQUEST_TIME_FLOAT
 REQUEST_TIME

 

Some important server elements


<?php
echo "Host: " . $_SERVER["HTTP_HOST"] . "<BR>";
echo "Browser: " . $_SERVER["HTTP_USER_AGENT"] . "<BR>";
echo "User's IP address: " . $_SERVER["REMOTE_ADDR"]."
";
echo "User's Software: " . $_SERVER["SERVER_SOFTWARE"]."
";
echo "User's name: " . $_SERVER["SERVER_NAME"]."
";
?>

 

Output


Host: localhost
Browser: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
User's IP address: ::1
User's Software: Apache/2.4.4 (Win64) PHP/5.4.12
User's name: localhost

 

Print complete server elements


<?php
echo "Complete Server Details";
foreach($_SERVER as $key => $value){
echo $key."=====".$value."</br>";
}
?>



PHP Interview PDF For Fresher

PHP Interview Question For fresher PDF

PHP Interview Question

pTutorial provides to its user the free interview pdf for fresher as well as experts. PHP is a very popular internet programming language that is basically used for creating dynamic web pages. PHP 5 introduce a lot of object oriented feature.

 

PHP interview question for fresher

These interview questions are very important for fresher who are going your first interview at company level.

This book also contains the PHP 5 MySql Questions, which are very useful for development and as well as for interview.You can easily download by clicking on download button.

Download PHP interview question for fresher



php-equals-operator

PHP Equal operator

PHP Equal operator

There are three equal operator or sign available in PHP.

php equals operator

  1. Assignment or single equal (=)
  2. Equality or double equal(==)
  3. Identical or triple equal(===)

Let us describe one by one with the help of the example.

PHP Single equal operator

Single equal operator is basically used for assigning the value to on the right to the variable on the left, as shown in the below example.

Syntax of PHP single equal operator

<?php

echo "Single Equal operator<br>";
$firstNumber=5;
$SecondNumber=10;
$sum=$firstNumber+$SecondNumber;
echo " Sum=$sum";

?>
Single Equal operator
Sum=15

Double equal operator

Double equal operator is used to checks the left and right value are equal, as shown in the example below.

Example of Double equal operator

<?php

echo "Double Equal operator<br>";
$a=5;
$b=10;
if($a==$b)
{
echo "Both are equal";	
}
else
{
echo "Both are not equal";	
}

?>

Output

Double Equal operator
Both are not equal

Triple equal operator

Triple equal operator is used to checks the left and right value are equal with same data type that means left value and right value must be in same data type.

Example of Triple equal operator

<?php

echo "Triple- Equal operator<br>";
$a=5;
$b=5.0;
if($a===$b)
{
echo "Both are equal";	
}
else
{
echo "Both are not equal";	
}

?>

Output

Triple- Equal operator
Both are not equal