32.How will you get the browser’s details using PHP?
One of the environemnt variables set by PHP is HTTP_USER_AGENT which identifies the user’s browser and operating system.
33.How will you generate random numbers using PHP?
The PHP rand() function is used to generate a random number. This function can generate numbers with-in a given range. The random number generator should be seeded to prevent a regular pattern of numbers being generated. This is achieved using the srand() function that specifiies the seed number as its argument.
34.What is the purpse $_PHP_SELF variable?
The PHP default variable $_PHP_SELF is used for the PHP script name and when you click “submit” button then same PHP script will be called.
35.How will you redirect a page using PHP?
The PHP header() function supplies raw HTTP headers to the browser and can be used to redirect it to another location. The redirection script should be at the very top of the page to prevent any other part of the page from loading. The target is specified by the Location: header as the argument to the header() function. After calling this function the exit() function can be used to halt parsing of rest of the code.
36.How can you display a file download dialog box using PHP?
The HTTP header will be different from the actual header where we send Content-Type as text/html\n\n. In this case content type will be application/octet-stream and actual file name will be concatenated alongwith it. For example,if you want make a FileName file downloadable from a given link then its syntax will be as follows.
# HTTP Header
print “Content-Type:application/octet-stream; name=\”FileName\”\r\n”;
print “Content-Disposition: attachment; filename=\”FileName\”\r\n\n”;
# Actual File Content
open( FILE, “<FileName” );
while(read(FILE, $buffer, 100) )
37.How will you get information sent via get method in PHP?
The PHP provides $_GET associative array to access all the sent information using GET method.
38.How will you get information sent via post method in PHP?
The PHP provides $_POST associative array to access all the sent information using POST method.
39.What is the purpse $_REQUEST variable?
The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. We will discuss $_COOKIE variable when we will explain about cookies. The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.
40.Which function will you use to create an array?
array() − Creates an array.