php server variables

Solutions on MaxInterview for php server variables by the best coders in the world

showing results for - "php server variables"
Amelie
09 May 2017
1echo $_SERVER['PHP_SELF'];
2echo "<br>";
3echo $_SERVER['SERVER_NAME'];
4echo "<br>";
5echo $_SERVER['HTTP_HOST'];
6echo "<br>";
7// echo $_SERVER['HTTP_REFERER'];
8echo "<br>";
9echo $_SERVER['HTTP_USER_AGENT'];
10echo "<br>";
11echo $_SERVER['SCRIPT_NAME'];
Yannik
14 Apr 2017
1//Just a PHP file to put on your local server (as I don't have enough memory)
2// Write the code by Md Abdur Rakib
3
4<?php
5$indicesServer = array('PHP_SELF',
6'argv',
7'argc',
8'GATEWAY_INTERFACE',
9'SERVER_ADDR',
10'SERVER_NAME',
11'SERVER_SOFTWARE',
12'SERVER_PROTOCOL',
13'REQUEST_METHOD',
14'REQUEST_TIME',
15'REQUEST_TIME_FLOAT',
16'QUERY_STRING',
17'DOCUMENT_ROOT',
18'HTTP_ACCEPT',
19'HTTP_ACCEPT_CHARSET',
20'HTTP_ACCEPT_ENCODING',
21'HTTP_ACCEPT_LANGUAGE',
22'HTTP_CONNECTION',
23'HTTP_HOST',
24'HTTP_REFERER',
25'HTTP_USER_AGENT',
26'HTTPS',
27'REMOTE_ADDR',
28'REMOTE_HOST',
29'REMOTE_PORT',
30'REMOTE_USER',
31'REDIRECT_REMOTE_USER',
32'SCRIPT_FILENAME',
33'SERVER_ADMIN',
34'SERVER_PORT',
35'SERVER_SIGNATURE',
36'PATH_TRANSLATED',
37'SCRIPT_NAME',
38'REQUEST_URI',
39'PHP_AUTH_DIGEST',
40'PHP_AUTH_USER',
41'PHP_AUTH_PW',
42'AUTH_TYPE',
43'PATH_INFO',
44'ORIG_PATH_INFO') ;
45
46echo '<table cellpadding="10">' ;
47foreach ($indicesServer as $arg) {
48    if (isset($_SERVER[$arg])) {
49        echo '<tr><td>'.$arg.'</td><td>' . $_SERVER[$arg] . '</td></tr>' ;
50    }
51    else {
52        echo '<tr><td>'.$arg.'</td><td>-</td></tr>' ;
53    }
54}
55echo '</table>' ;
56
57/*
58
59That will give you the result of each variable like (if the file is server_indices.php at the root and Apache Web directory is in E:\web) :
60
61PHP_SELF    /server_indices.php
62argv    -
63argc    -
64GATEWAY_INTERFACE    CGI/1.1
65SERVER_ADDR    127.0.0.1
66SERVER_NAME    localhost
67SERVER_SOFTWARE    Apache/2.2.22 (Win64) PHP/5.3.13
68SERVER_PROTOCOL    HTTP/1.1
69REQUEST_METHOD    GET
70REQUEST_TIME    1361542579
71REQUEST_TIME_FLOAT    -
72QUERY_STRING   
73DOCUMENT_ROOT    E:/web/
74HTTP_ACCEPT    text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
75HTTP_ACCEPT_CHARSET    ISO-8859-1,utf-8;q=0.7,*;q=0.3
76HTTP_ACCEPT_ENCODING    gzip,deflate,sdch
77HTTP_ACCEPT_LANGUAGE    fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
78HTTP_CONNECTION    keep-alive
79HTTP_HOST    localhost
80HTTP_REFERER    http://localhost/
81HTTP_USER_AGENT    Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17
82HTTPS    -
83REMOTE_ADDR    127.0.0.1
84REMOTE_HOST    -
85REMOTE_PORT    65037
86REMOTE_USER    -
87REDIRECT_REMOTE_USER    -
88SCRIPT_FILENAME    E:/web/server_indices.php
89SERVER_ADMIN    myemail@personal.us
90SERVER_PORT    80
91SERVER_SIGNATURE   
92PATH_TRANSLATED    -
93SCRIPT_NAME    /server_indices.php
94REQUEST_URI    /server_indices.php
95PHP_AUTH_DIGEST    -
96PHP_AUTH_USER    -
97PHP_AUTH_PW    -
98AUTH_TYPE    -
99PATH_INFO    -
100ORIG_PATH_INFO    -
101
102*/
103?>
104
Isabelle
18 Jan 2020
1<?php
2  // PHP $_SERVER['...']; method
3  
4  // PHP file name
5  echo 'PHP file name: '.$_SERVER['PHP_SELF'].'<br>';
6  // Server name
7  echo 'Server name: '.$_SERVER['SERVER_NAME'].'<br>';
8  // HTTP host
9  echo 'HTTP host: '.$_SERVER['HTTP_HOST'].'<br>';
10  // Refering link
11  echo 'Refering link: '.$_SERVER['HTTP_REFERER'].'<br>';
12  // User agent
13  echo 'User agent: '.$_SERVER['HTTP_USER_AGENT'].'<br>';
14  // Script name
15  echo 'Script name: '.$_SERVER['SCRIPT_NAME'];
16  
17  // The rest is optional
18
19  if($_SERVER['PHP_SELF']=='/filename.php'){
20    //If there is no folder
21    echo 'No folder'.$_SERVER['PHP_SELF'];
22  } else{
23    // Echo the name of the folder containing the PHP file
24    echo 'PHP file name: '.$_SERVER['PHP_SELF'];
25  }
26  
27  // The same if statements can be used for the script name
28  
29  if($_SERVER['SCRIPT_NAME']=='/filename.php'){
30    // If there is no folder
31    echo 'No folder'.$_SERVER['SCRIPT_NAME'];
32  } else{
33    // Echo the name of the folder containing the PHP file
34    echo 'PHP file name: '.$_SERVER['SCRIPT_NAME'];
35  }
36  
37  echo '<a href="repl.it/@CoolWebDev">More from me...</a>';
38  
39  // I hope you found this helpful! 
40?>
queries leading to this page
php server dataserver request method in php 24 server in phpphp server httpphp request uri 27php apache create server variablesphp check server side usage detailshow to known from where user call the server in phpurl 24 server phpphp getting the server nameservername in phphttp referer php php netscript server phpserver http host in env 24 server list phpphp 24 server 27http referer 27globals server php selfserver php remote addrphp 24 server 5b 27query string 27 5dphp print server variablesphp server requesthttp port php server htmlphp server variablesphp request uriserver var phpphp 25 24 serverphp echo serverserver http refererwhere can i find 24 serverserver name phpphp 24 server server namephp server in html scripthttp 3a 2f 2f 24 server 5bhttp host 5d 24 server 5b 24 request uri 5dphp 24 server 5b 27server name 27 5d 3bphp function serverhttp referer in phpserver php se c3 b2fphp 24 server 27php self 27php 7 24 server 5b 27http host 27 5dquery string phpphp http variablesphp get server dataphp server port server 5b 22php self 22 5dphp http hostserver addr php 24server phpserver php selfphp change key name 24 server 27remote addr 27 phpserver uri phpphp get accept headerserver in phphow to use server variable in php 24 server php selfdefining the absolute path of a php variable on a live hosting platformall 24 server options 24 server php ip addresserver php selfphp server functionhttp server 7baddr 3a variablephp 7 4 server 5b 27http host 27 5dphp server remote addressphp get host addressphp server namephp script filenamehow to get server name in phpphp server hostnamelocal addr in phpserver request in phpphp server varserver array in phpphp 24 server 5b 27 24 server request phpphp serve on address server phpphp server componentsscript filenamephp url serverphp 24serverphp server query stringget server name in phpphp get http hostall 24 server 24 server 27path info 27 phpphp update 24 server variable while script runningphp refer host 24 server 5b 27request uri 27 5d 27 22 method 3d 22post 22 3e first name 3a 24server variable phpphp request uriphp server addrwh3schools php 24 server 3c 3fphp server selfuser agest and server ip phpphp 24remote addrhttphost phpphp server headers remote addr 28 24 server 5b 5d 29php print all 24 serverphp scripts to get server informationserver name in phphttp host phpphp php selfserver port phpphp servername 24 server 27http host 27 in phpphp add server super globalphp server protocolphp get server variablesserver php selgphp server script filename 24 server variablesserver php 24 server 27server name 27 in phpphp server request uriretrieve server variable phprequest uri phpget request host phpphp host locationphp server addrphp 24 server 5b 22query string 22 5d 24 server examplephp 3cservervariables 3ehttp 2f 2flocalhost 2fvariables phpenvironment url phpget server request uri phpphp 24 server variablesphp get server informationphp 24 server 28 27request time 27 29 errorindex php by server ip and usernameurl server phpphp variable with heare script locationget all server info in phphttp referer phpset server name phpphp hostphp server http hostserver port phpphp apache remote portphp 24 server 5b 27script name 27 5dphp server nameusage of php server http functionrequest uri php methodphp request uri partphp serve get requestphp server vars 24 server 5b 27remote addr 27 5d headerphp 24server variables server php self 24 server 5b 27server name 27 5d don 27t have httpsserver phpphp server 5b 27server name 27 5dserver referer in phpserver variables in phpchange server name phpserver 27php self 27php autoscript from serverphp server script 24 server 27request time 27 in phpphp server server namehow to set server variable in phpphp server information scriptphp no server addressphp echo server nameserver global variable php 40 24 server in php 40 startingserver variables phpserver name 24 server phpphp url with server variablespropeties php serverphp server request methodif server php 24 server 5b 22phpphp http refererrequest uri php server uriproperties server in phpserver remote address phpphp server parameters server in phphow to use 24 request 5b 27path 27 5d in phpphp get server infophp 24 server 5b 27server name 27 5dphp server hostecho 24 server 5b 27server addr 27 5drequest method serverserver functions phpwhat does 24 server do php 24 server 5b 27http host 27 5dttp server 7baddr 3a variableserver variable phpphp get all server variablesphp server name host examplesend server uri in phpphp check server nameserver superglobal phpphp server variable not availablephp server functionsphp 40 24 server server name localhost productionlocalhost variables phpset 24 server 5b 27http host 27 5d in envphp 24 server 5b 5dserver self phphow to check php request to the server 24 server 5b 22server name 22 5d to detect host automaticallyphp get server addressserver request uri php 24server request uriphp variables 24 serverphp server methodwhat is the http host variable and php 24server in phpip server phpphp server variable not available document rootphp eval functionwhere do i find the server name config file in php 24 server 27http referer 27 in phpphp set server variablephp servername on onlinephp server http host outputget data php server namephp request methodphp 24 server 5b 27https host 27 5dglobal variable ip address php serverphp set servernamephp serv sitehost addr phpphp server refererphp server name 24 server 27https 27 php propeties php serverwhat is 24 server 5b 27http host 27 5d in phpserver domain name phpphp server pgp selfhow to get host in php 24 server 24 server return 24 server php maulphp get server addreeserver host name phpis php 3c 3f 3d supported on all servers 3fphp server php selfphp server get dataphp server user agentphp 24 server 27request uri 27server request uri 24 server of requestserver method in phpphp const 24 server list 24 server 27query string 27 in phpget server name phpphp request uriphp 24 server 5b 27http host 27 5d 24 server 27http host 27 returnwhat is 24 server in phpphp servername vs hostserver to server http phpphp server request uriphp serve nameserver request page phpserver global variables 24 server 27remote addr 27 exampleset server php server request uri in php 24server 3d 24 server 5b 27remote addr 27 5d 3b if 28 24server 3d 3d 27 3a 3a1 27 or 24server 3d 3d 27localhost 27 or 24server 3d 3d 27127 0 0 1 27 29 7b define 28 27host 27 2c 27localhost 3a3306 27 29 3b define 28 27user 27 2c 27root 27 29 3bphp 7 4 http hostremote addr phpphp dont enter global 24 server 5b 27http host 27 5d directlyphp 24 server name 24 server 5b 27http uri 27 5d phpglobal 24 server 5b 27remote addr 27how to use 24 server 5b 27remote port 27 5d in laravel 24 server 5b 22request uri 22 5d exampleprint servername phphow to know server name in phpget server information php php url server variablephp 24 server http or https 3d 24 in phphttp referrer phphttp host examplephp get servernameserver parameters phpphp self with server namephp server phpitself 24vars 3d isset 28 24 server 29 3f 24 server 3a 28isset 28 24http server vars 29 3f 24http server vars 3a array 28 29 29request uri server variableserver host in php 24server name in php 24 server 5b 5d php 24 server 27http host 27 localhostphp code for access client processor numberserver name in php wsserver address 28 29how we 24 server in phpwhat is unique value for 24 server in phpphp server methodsphp no server addrphp server ipphp 24 server header variablephp server variables exampleshost in phphttp host php 24 server 5b 27http host 27 5d pathphp serve globalall php server functionsserver request method phpw3schools request url phpreferer php serverphp 24 server 5b 27request method 27 5d 3d 3d 3d 27update 27php http hostget http hostphp get hostserver elements phpphp 24 server request uri 24 server 27http host 27 examplephp 24 server 5b 27http x classmarker hmac sha256 27 5dpublic function selectproduct 28request 24 server 29get host phpphp 24 server 5b 27https 27 5dhow to get the server name in phpsql get server namephp sever globalrequest uri in phpservername for php php 24 server 24 server 27request uri 27 phpphp server variablehow to test 24 server in phpserver user agent phptest php 3f name 3d 3c 3fphp 24 server 5b 27name 27 5d 3b 3f 3ephp serverphp all server variablesphp server error echo super globalservername phpphp 24 server 27request uri 27 outputphp picture php server request methodphp is 24 server 5b 27http host 27 5dphp selftphp 24 server 5b 27http acceptserver requested uri 24 server functions phpphp add var to serverserver address phphttp 3a 2f 2fapache org 2fdoc 2f2 4 2flicense htmlphp server headerserver ip phpserver with php dataphp server globalhttp referer server phpphp 24 server 5b 27http accept 27if 28 24 request 5b 27server addr 27 5dphp server http host 24 server property php 24 server phpserver request method php 7 4server referer phpphp server httpsphp how to turn server variable https onphp server path infouse 24 server in phpserver method php 24 server 5b 27remote addr 27 5d http headerphp sever selfget server address 2b phpphp 24 server listserver name phpusage of php server functionhow to find if php is using 24 server or 24http server varsphp script uriphp 24 server 27script name 27find site server using phpphp get server namephp dump and die server urlphp server addressphp server variables