PHP FILES ENV COOKIE SESSION

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : $_FILES, $_ENV, $_COOKIE, $_SESSION

PHP : $_FILES

Description

$_FILES is a super global variable which can be used to upload files. Here we will see an example in which our php script checks if the form to upload the file is being submitted and generates a message if true.

Here is the html code (upload.php): 

view plaincopy to clipboardprint?

  

  1.  

  2.  

  3.  

     
  4. enctype="multipart/form-data">  

  5. Filename:  

  6.   


  7.   

  8.   

  9.   

  10.   

  11.    

Code of files.php file:

view plaincopy to clipboardprint?

  1. if ($_FILES["file"] > 0)  

  2.   {  

  3.   echo "You have selected a file to upload";  

  4.   }  

  5. ?>  

PHP : $_ENV

Description

$_ENV is used to return the environment variables from the web server.

view plaincopy to clipboardprint?

  1. echo $_ENV['username'];
      

  2. ?>  

Example of $_ENV

view plaincopy to clipboardprint?

  1. echo "my username is ".$_ENV['username'];  

  2. ?>  

PHP : $_COOKIE

Description

Cookies are small text files loaded from a server to a client computer storing some information regarding the client computer, so that when the same page from the server is visited by the user, necessary information can be collected from the cookie itself, decreasing the latency to open the page.

$_COOKIE retrieves those cookies.

view plaincopy to clipboardprint?

  1. setrawcookie();  

  2. print_r($_COOKIE);  

  3. ?>  

PHP : $_SESSION

Description

Sessions are wonderful ways to pass variables. All you need to do is start a session by session_start();Then all the variables you store within a $_SESSION, you can access it from anywhere on the server. Here is an example:  

Example of $_SESSION

view plaincopy to clipboardprint?

  1. session_start();  

  2. $_SESSION['w3resource']='The largest online tutorial';  

  3. echo $_SESSION['w3resource'];  

  4. ?>