Explain the purpose of output buffering in PHP.List out different arguments in PHP header function?How do I find out the number of parameters passed into function ?What Are the File Upload Settings in Configuration File?How can you access a COM object from a PHP page?How can we know the count/number of elements of an array?How session works (internal processing of session)?How many ways I can redirect a PHP page? ~ Interview Questions & Answers

Sunday, June 27, 2010

Explain the purpose of output buffering in PHP.

Output buffering in PHP buffers a scripts output. This buffer can be edited before returning it to the client. Without output buffering, PHP sends data to the web server as soon as it is ready. Output buffering "send" cookies at any point in the script. Cookies do not have to be necessarily sent near the start of page. Output buffers are stackable and hence sending to output is by choice.

Friday, June 18, 2010

List out different arguments in PHP header function?

void header ( string string [, bool replace [, int http_response_code]])

Sunday, June 13, 2010

How do I find out the number of parameters passed into function ?

func_num_args() function returns the number of parameters passed in.

Tuesday, June 8, 2010

What Are the File Upload Settings in Configuration File?

There are several settings in the PHP configuration file related to file uploading:
• file_uploads = On/Off - Whether or not to allow HTTP file uploads.
• upload_tmp_dir = directory - The temporary directory used for storing files when doing file upload.
• upload_max_filesize = size - The maximum size of an uploaded file.

Saturday, June 5, 2010

How can you access a COM object from a PHP page?

By utilizing the com_load and the dotnet_load respectively
you can incorporate COM objects and .NET libraries into your
PHP code, thus anytime you see "library code" in a question,
make sure you remember these two functions.
com_load — Creates a new reference to a COM component [deprecated]
Deprecated, use the OO syntax instead.
<?php
// do this
$obj = new COM($module);
// instead of this:
$obj = com_load($module);
?>

How can we know the count/number of elements of an array?

2 ways:
a) sizeof($array_name) - This function is an alias of count()
b) count($array_name) - This function returns the number of elements in an array.
Interestingly if you just pass a simple var instead of an array, count() will return 1.

Thursday, June 3, 2010

How session works (internal processing of session)?

To start a session:
– session_start()
– Creates a session identifier
– Session identifier is passed between client and server either as a Cookie, or in GET parameters
Then, can create, access, and modify session variables:
– $_SESSION[session_var_name] = value;
– $_SESSION is only available once you call session_start()
– $local_variable = $_SESSION[session_var_name];
– Can check if session variable is set by using isset();
To end a session:
– session_destroy();

How many ways I can redirect a PHP page?

a. Header function in PHP redirects to a new URL
Example:
<?php
header("Location: http://www.redirecturl.com/");
?>
b. http_redirect() is also used to redirect to a new page or URL.
Syntax
void http_redirect ( [string url [, array params [, bool session = FALSE [, int status]]]] )
Here, the URL is the path of the new page. params can be some query parameters followed by whether the session information needs to be passed and the custom response status code.