R SOFT PHP – INTERVIEW QUESTIONS WITH ANSWERS

R SOFT PHP – INTERVIEW QUESTIONS WITH ANSWERS

This blog explains about R SOFT PHP – INTERVIEW QUESTIONS WITH ANSWERS . Some of them are explained very well below :

_______________________________________________________________________________

 1. What do you mean by Get method ?

                                       The GET Method

The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ?character.

  • The GET method produces a long string that appears in your server logs, in the browser’s Location: box.
  • The GET method is restricted to send upto 1024 characters only.
  • Never use GET method if you have password or other sensitive information to be sent to the server.
  • GET can’t be used to send binary data, like images or word documents, to the server.
  • The data sent by GET method can be accessed using QUERY_STRING environment variable.
  • The PHP provides $_GETassociative array to access all the sent information using GET method.

Try out following example by putting the source code in test.php script.

<?php

   if( $_GET[“name”] || $_GET[“age”] ) {

      echo “Welcome “. $_GET[‘name’]. “<br />”;

      echo “You are “. $_GET[‘age’]. ” years old.”;

 

      exit();

   }

?>

<html>

   <body>

 

      <form action = “<?php $_PHP_SELF ?>” method = “GET”>

         Name: <input type = “text” name = “name” />

         Age: <input type = “text” name = “age” />

         <input type = “submit” />

      </form>

 

   </body>

</html>

 

____________________________________________________________________

2. Explain briefly about Post method ?

                                               The POST Method

The POST method transfers information via HTTP headers. The information is encoded as described in case of GET method and put into a header called QUERY_STRING.

  • The POST method does not have any restriction on data size to be sent.
  • The POST method can be used to send ASCII as well as binary data.
  • The data sent by POST method goes through HTTP header so security depends on HTTP protocol. By using Secure HTTP you can make sure that your information is secure.
  • The PHP provides $_POST associative array to access all the sent information using POST method.

Try out following example by putting the source code in test.php script.

<?php

   if( $_POST[“name”] || $_POST[“age”] ) {

      if (preg_match(“/[^A-Za-z’-]/”,$_POST[‘name’] )) {

         die (“invalid name and name should be alpha”);

      }

      echo “Welcome “. $_POST[‘name’]. “<br />”;

      echo “You are “. $_POST[‘age’]. ” years old.”;

 

      exit();

   }

?>

<html>

   <body>

 

      <form action = “<?php $_PHP_SELF ?>” method = “POST”>

         Name: <input type = “text” name = “name” />

         Age: <input type = “text” name = “age” />

         <input type = “submit” />

      </form>

 

   </body>

</html>

________________________________________________________________________

3. Explain about the term Cookies in PHP ? 

                                                       COOKIES

Cookies are text files stored on the client computer and they are kept of use tracking purpose. PHP transparently supports HTTP cookies.

There are three steps involved in identifying returning users −

  • Server script sends a set of cookies to the browser. For example name, age, or identification number etc.
  • Browser stores this information on local machine for future use.
  • When next time browser sends any request to web server then it sends those cookies information to the server and server uses that information to identify the user.

_______________________________________________________________________________________

 REFERENCES : 

https://www.tutorialspoint.com/php/php_get_post.htm

https://www.guru99.com/php-forms-handling.html