Results 1 to 6 of 6

Thread: What are the server variables in PHP?

  1. #1
    Join Date
    Jul 2010
    Posts
    29

    What are the server variables in PHP?

    Let me tell you first that I have recently started leaning PHP, so I am not having great knowledge about it. I am having some idea about the PHP variable, but I am not knowing what is server variable. We have given an assignment to write about an server variables that are used in PHP. A variable is a memory that will contain data, this data may change over time. But then what are the server variables? I am hoping that somebody over your side will help me soon by providing necessary notes.

  2. #2
    Join Date
    Oct 2008
    Posts
    115

    Re: What are the server variables in PHP?

    Predefined variables are variables included in PHP that avoid the use of many functions to get the same result. They are very useful and can get information on the client and server. These are the variables classified by type. The following are the server variables:
    • $ _SERVER ['PHP_SELF'] - Give the tree of the current page starting from the root of your site (if PHP is running in command line variable is not available)
    • $ _SERVER ['GATEWAY_INTERFACE'] contains the revision number of the CGI server
    • $ _SERVER ['SERVER_NAME'] - Name of the host server that is running the script.
    • $ _SERVER ['SERVER_PROTOCOL'] - Name and revision of the communication protocol: HTTP/1.0
    • $ _SERVER ['REQUEST_METHOD'] - Request method used to access the page: 'GET', 'HEAD', 'POST' or 'PUT'
    • $ _SERVER ['QUERY_STRING'] - Give the arguments placed after the question mark if they exist in the URL.
    • $ _SERVER ['DOCUMENT_ROOT'] - Root of your site.
    • $ _SERVER ['HTTP_ACCEPT_ENCODING'] - Contents of the Accept-Encoding: the current request, if it exists. For example: 'gzip'.
    • $ _SERVER ['HTTP_ACCEPT_LANGUAGE'] - Language used by your browser: 'en'
    • $ _SERVER ['HTTP_REFERER'] - This is the page address in which the customer came to your site. Some browsers allow you to change this value, and some firewalls block it.
    • $ _SERVER ['HTTP_USER_AGENT'] - Browser used by the client.
    • $ _SERVER ['REMOTE_ADDR'] - Ip address of the client.
    • $ _SERVER ['REMOTE_HOST'] - Reverse DNS that allows to set the hostname of the client IP
    • $ _SERVER ['REMOTE_PORT'] - Port used (usually 80) to send and receive data between the HTTP server and client.
    • $ _SERVER ['SCRIPT_FILENAME'] - Absolute path of the current script.
    • $ _SERVER ['PATH_TRANSLATED'] - Path that points to the current script.
    • $ _SERVER ['SCRIPT_NAME'] - Name of the current page.
    • $ _SERVER ['REQUEST_URI'] - URI used to access the current page, / manage.php example.

  3. #3
    Join Date
    Oct 2008
    Posts
    116

    Re: What are the server variables in PHP?

    There are also some other predefined variables that are used in PHP:
    • $ GLOBALS: this table contains all global variables defined.
    • $ _GET: This table contains all the variables from the current URL.
    • $ _POST: This table contains all the variables from a form post method.
    • $ _SERVER: This table contains all the variables provided by the Web server or the client.
    • $ _COOKIE: This table contains all the names and values of cookies sent by the client.
    • $ _FILES: This table contains the variables provided by the browser during a file upload by the client.
    • $ _ENV: This table contains all the variables from the PHP environment.
    • $ _REQUEST: This table contains all the variables supplied via an input script (GET, POST, COOKIE ... for example).
    • $ _SESSION: This table contains all the session variables used.

  4. #4
    Join Date
    Jan 2009
    Posts
    124

    Re: What are the server variables in PHP?

    The PHP language is not very typical, ie a variable can alternatively be a number, string or whatever else! The main data types in PHP (this will not change almost anything for you in terms of syntax, but it is good to know. Note that the variable names used as an example and their values are purely arbitrary. String: the value is delimited by quotes (single or double, it will favor a simple matter of speed):
    PHP Code:
    <?php 
    $first_name 
    'DuraCell' 
    ?>
    A number: it removes the quotes this time, it allows PHP to tell that this is a number (either integer or floating):
    PHP Code:
    <?php 
    $name 

    $name 3.02 
    ?>
    A boolean: Boolean variables can take two values: TRUE (true) and false (false). They may be useful to know if such an option is enabled:
    PHP Code:
    <?php 
    $view_options 
    FALSE // not display options
    $use_cache TRUE // using a cache
    ?>

  5. #5
    Join Date
    Dec 2008
    Posts
    112

    Re: What are the server variables in PHP?

    Do you ever happened to come across pages with url extending that style? : Page.php? Param1 = value & param2 = other_value (and so on)? PHP will allow you to retrieve the name and value parameters that are in your URL if there a. This is useful for example to pass variables and values from page to page (exceptionally, for you shall see that there is a better way to do this in further deepening of PHP). Before using this principle to your pages, you have to pay attention to the cons by passing variables. In fact, if you do the treatments on these variables (or if you use its value) must be careful about certain things, including the following:
    • If you want to show the value of the variable, it is necessary that if someone types in HTML in the address bar, it is displayed and not considered as code because anyone can put anything (javascript displays a message box until the recovery of confidential cookies on the client PC).
    • If you use the value in a query database (if you do not know what a database do not worry, we'll see it after all), we must protect the query by using protective functions as mysql_real_escape_string () for a MySQL database.
    Now imagine that you want to offer a service display name to webmasters. They will call a page on your site with parameters in the address, and your page will return the name that is in the url.

  6. #6
    Join Date
    Apr 2009
    Posts
    79

    Re: What are the server variables in PHP?

    $ _GET Variables are part of what we call superglobals. This tells you nothing at the moment, but know that they are variables accessible from anywhere (we will see later that the variables can not be used everywhere, and well superglobals can be, basically this is a major difference that separates them from others). Well it is nice you tell me the variables $ _GET, but it is not necessarily what you want. If you want to retrieve the age of a visitor that he has entered into a text box via the post method of a form, you will have to use this time named variables $ _POST. The principle is exactly the same as $ _GET variables.

Similar Threads

  1. What are the PHP Variables?
    By shivendra in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 07:05 PM
  2. Constant Variables in C++
    By Gomeler in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 09:11 AM
  3. Flash Variables to ASP
    By Mindstorm in forum Software Development
    Replies: 3
    Last Post: 31-10-2009, 06:07 PM
  4. c# environment variables
    By EULALIA in forum Software Development
    Replies: 3
    Last Post: 13-07-2009, 02:23 PM
  5. Variables to use in many forms!
    By RupaliP in forum Software Development
    Replies: 3
    Last Post: 19-02-2009, 11:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,000,892.75748 seconds with 16 queries