Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Tutorials > PHP Tutorials

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

PHP Tutorials PHP Tutorials

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-22-2007, 09:43 PM
Jaan's Avatar   
Jaan Jaan is offline
<img src="http://forum.codecall.net/images/userbar/mod.png" alt="Mod">
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 887
Last Blog:
Wadio Media Layout Com...
Credits: 56
Rep Power: 15
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Global variables (SERVER)

This tutorial will show you how you can use $_SERVER[] variables..

$_SERVER['DOCUMENT_ROOT']

PHP Code:
<?php
echo $_SERVER['DOCUMENT_ROOT'];
?>
The document root directory under which the current script is executing, as defined in the server's configuration file.


$_SERVER['GATEWAY_INTERFACE']

PHP Code:
<?php
echo $_SERVER['GATEWAY_INTERFACE'];
?>
What revision of the CGI specification the server is using; i.e. 'CGI/1.1'.

$_SERVER['HTTP_ACCEPT']

PHP Code:
<?php
echo $_SERVER['HTTP_ACCEPT'];
?>
Contents of the Accept: header from the current request, if there is one.

$_SERVER['HTTP_ACCEPT_CHARSET']

PHP Code:
<?php
echo $_SERVER['HTTP_ACCEPT_CHARSET'];
?>
Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.

$_SERVER['HTTP_ACCEPT_ENCODING']

PHP Code:
<?php
echo $_SERVER['HTTP_ACCEPT_ENCODING'];
?>
Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'.

$_SERVER['HTTP_ACCEPT_LANGUAGE']

PHP Code:
<?php
echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];
?>
Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'.

$_SERVER['HTTP_CONNECTION']

PHP Code:
<?php
echo $_SERVER['HTTP_CONNECTION'];
?>
Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'.

$_SERVER['HTTP_HOST']

PHP Code:
<?php
echo $_SERVER['HTTP_HOST'];
?>
Contents of the Host: header from the current request, if there is one.

$_SERVER['HTTP_REFERER']

PHP Code:
<?php
echo $_SERVER['HTTP_REFERER'];
?>
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

$_SERVER['HTTP_USER_AGENT']

PHP Code:
<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>
Contents of the User-Agent: header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent.

$_SERVER['PATH_TRANSLATED']

PHP Code:
<?php
echo $_SERVER['PATH_TRANSLATED'];
?>
Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.

Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly under the Apache 2 SAPI in contrast to the situation in Apache 1, where it's set to the same value as the SCRIPT_FILENAME server variable when it's not populated by Apache. This change was made to comply with the CGI specification that PATH_TRANSLATED should only exist if PATH_INFO is defined.

Apache 2 users may use AcceptPathInfo = On inside httpd.conf to define PATH_INFO.

$_SERVER['PHP_SELF']

PHP Code:
<?php
echo $_SERVER['PHP_SELF'];
?>
The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.

If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.

$_SERVER['QUERY_STRING']

PHP Code:
<?php
echo $_SERVER['QUERY_STRING'];
?>
The query string, if any, via which the page was accessed.

$_SERVER['REMOTE_ADDR']

PHP Code:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>
The IP address from which the user is viewing the current page.

$_SERVER['REMOTE_PORT']

PHP Code:
<?php
echo $_SERVER['REMOTE_PORT'];
?>
The port being used on the user's machine to communicate with the web server.

$_SERVER['REQUEST_METHOD']

PHP Code:
<?php
echo $_SERVER['REQUEST_METHOD'];
?>
Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
Note: PHP script is terminated after sending headers (it means after producing any output without output buffering) if the request method was HEAD.

$_SERVER['REQUEST_URI']

PHP Code:
<?php
echo $_SERVER['REQUEST_URI'];
?>
The URI which was given in order to access this page; for instance, '/index.html'.

$_SERVER['SCRIPT_FILENAME']

PHP Code:
<?php
echo $_SERVER['SCRIPT_FILENAME'];
?>
The absolute pathname of the currently executing script.
Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.

$_SERVER['SCRIPT_NAME']

PHP Code:
<?php
echo $_SERVER['SCRIPT_NAME'];
?>
Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.

$_SERVER['SERVER_ADMIN']

PHP Code:
<?php
echo $_SERVER['SERVER_ADMIN'];
?>
The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host.

$_SERVER['SERVER_NAME']

PHP Code:
<?php
echo $_SERVER['SERVER_NAME'];
?>
The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

$_SERVER['SERVER_PORT']

PHP Code:
<?php
echo $_SERVER['SERVER_PORT'];
?>
The port on the server machine being used by the web server for communication. For default setups, this will be '80'; using SSL, for instance, will change this to whatever your defined secure HTTP port is.

$_SERVER['SERVER_PROTOCOL']
PHP Code:
<?php
echo $_SERVER['SERVER_PROTOCOL'];
?>
Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';

$_SERVER['SERVER_SIGNATURE']

PHP Code:
<?php
echo $_SERVER['SERVER_SIGNATURE'];
?>
String containing the server version and virtual host name which are added to server-generated pages, if enabled.

$_SERVER['SERVER_SOFTWARE']
PHP Code:
<?php
echo $_SERVER['SERVER_SOFTWARE'];
?>
Server identification string, given in the headers when responding to requests.

Info taken from php.net
some of those echo example might not work because some of those variables don't have output!
__________________


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
| Need help? Send a
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delphi Sockets : Simple client and server program tosh5457 Pascal/Delphi 0 05-26-2007 11:00 AM
C- Syntax to allocate Global variables to consecutive memory locations techie82 C and C++ 1 04-09-2007 11:42 AM
Tutorial: Proxy Servers Lop Tutorials 7 01-02-2007 03:53 AM
game server mod John C and C++ 8 08-20-2006 10:01 AM
Howto use global variables dirkfirst PHP Forum 4 07-15-2006 02:19 PM


All times are GMT -5. The time now is 11:24 PM.

Contest Stats

Xav ........ 1276.19
MeTh0Dz|Reb0rn ........ 1048.58
marwex89 ........ 869.98
John ........ 868.39
morefood2001 ........ 868.04
WingedPanther ........ 761.06
Brandon W ........ 684.87
chili5 ........ 294.12
Steve.L ........ 216.18
dargueta ........ 192.86

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 81%

Ads