Question-51. Can you assign the default values to a function parameters ?

Answer- Yes! You can set a parameter to have a default value if the function’s caller doesn’t pass it.

Question-52. How will you set cookies using PHP ?

Answer- PHP provided setcookie() function to set a cookie. This function requires upto six arguments and should be called beforetag. For each cookie this function has to be called separately.

setcookie(name, value, expire, path, domain, security);

 

Question-53. How will you get cookies using PHP ?

Answer- PHP provides many ways to access cookies. Simplest way is to use either $_COOKIE or $HTTP_COOKIE_VARS variables.

Question-54. How will you make a check that a cookie is set or not ?

Answer- You can use isset() function to check if a cookie is set or not.

Question-55. How will you delete a cookie ?

Answer- To delete a cookie you should call setcookie() with the name argument only.

Question-56. How will you start a session in PHP ?

Answer- A PHP session is easily started by making a call to the session_start() function. This function first checks if a session is already started and if none is started then it starts one. It is recommended to put the call to session_start() at the beginning of the page.

Question-57. How will you access session variables in PHP ?

Answer- Session variables are stored in associative array called $_SESSION[]. These variables can be accessed during lifetime of a session.

Question-58. How will you check if session variable is already set or not in PHP ?

Answer- Make use of isset() function to check if session variable is already set or not.

Question-59. How will you unset a single session variable ?

Answer- Here is the example to unset a single variable −

   unset($_SESSION['counter']);

 

Question-60. How will you destroy the session ?

Answer- A PHP session can be destroyed by session_destroy() function.