Results 1 to 6 of 6

Thread: What are the Predefined Variables in PHP?

  1. #1
    Join Date
    Apr 2009
    Posts
    393

    What are the Predefined Variables in PHP?

    Hi friends,
    I have recently started learning the PHP programming language. So I am not having enough knowledge about it. I want to know about the variables that are predefined in PHP. I thought that last time you guys helped me lot, so it would be helpful to post doubt this time also.!! Please tell me what are the Predefined Variables in PHP? Since I am new, please explain me in details.!!

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What are the Predefined Variables in PHP?

    Since, you are new to the PHP programming languages. You should first clear the concept of the variables. Otherwise, you will face a problem while doing the coding for the PHP. PHP provides a large number of predefined variables available to your scripts. These variables account for almost everything from variable external environment variables included in PHP through the latest error messages or headers recovered. Several predefined variables in PHP are "super", which means they are available whatever the context of the script. It is unnecessary to do global $ variable; to access it within functions or methods.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: What are the Predefined Variables in PHP?

    You can also use the variables from an external sources. I would like to explain you that since it is very important from the coding point of view. When a form is sent to a PHP script, all the form variables are automatically available in the script. For example, consider the following form :
    PHP Code:
    <form action="demo.php" method="post">
         
    Name: <input name="username" /> <br />
         
    Email: <input name="email" /> <br />
         <
    input type "submit" name "submit" value "Submit!"  />
     </ 
    form

  4. #4
    Join Date
    Nov 2005
    Posts
    1,323

    Re: What are the Predefined Variables in PHP?

    Using a GET form is similar, except that you must use the predefined variables of GET instead. GET also applies to the QUERY_STRING. Depending on your particular setup and your preferences, you have several ways to access data from forms. The following code explains you about that :
    PHP Code:
    <?php 
    echo $_POST 'username' ]; 
    echo 
    $_REQUEST 'username' ]; 

    import_request_variables 'p' 'p_' ); 
    echo 
    $p_username 
    echo 
    $HTTP_POST_VARS 'username' ]; 

    echo 
    $username 
    ?>
    The above coding explains you about the accessing data from a simple POST HTML form.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What are the Predefined Variables in PHP?

    PHP also understands arrays in the context of forms. Because PHP determines the types of variables and converts them as needed, it is not always the type of variable you want. PHP includes functions for determining the type of a variable: GetType (), is_array (), is_float (), is_int (), is_object () and is_string (). You should keep in mind that by default, all superglobals are available, and only the configuration directives may make them unavailable.The super-globals are :
    • $ GLOBALS
    • $ _SERVER
    • $ _GET
    • $ _POST
    • $ _FILES
    • $ _COOKIE
    • $ _SESSION
    • $ _REQUEST
    • $ _ENV

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: What are the Predefined Variables in PHP?

    You can use superglobals to make your variables available everywhere without declaring them global. The following coding demonstrates the same :
    PHP Code:
    <?php 

    $_ENV 
    'mystring' ] = 'Hello World' 
    $_ENV 'myarray' ] = array( 'Alpha' 'Beta' 'Gamma' ); 

    function 
    test () { 
    print 
    $_ENV 'mystring' ]; 
    print_r $_ENV 'myarray' ]); 


    test (); 

    ?>

Similar Threads

  1. Replies: 4
    Last Post: 28-02-2010, 02:10 AM
  2. What are the PHP Variables?
    By shivendra in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 07:05 PM
  3. Flash Variables to ASP
    By Mindstorm in forum Software Development
    Replies: 3
    Last Post: 31-10-2009, 06:07 PM
  4. Variables in .bat files
    By jackz in forum Software Development
    Replies: 3
    Last Post: 30-07-2009, 10:33 PM
  5. c# environment variables
    By EULALIA in forum Software Development
    Replies: 3
    Last Post: 13-07-2009, 02:23 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,019,866.95859 seconds with 17 queries