Your Ad Here
Showing posts with label web languages. Show all posts
Showing posts with label web languages. Show all posts

Sunday, January 11, 2009

PHP Programming

Q : How To Download and Install PHP for Windows?
A : The best way to download and install PHP on Windows systems is to:
which is the official Web site for PHP.
Download PHP binary version for Windows in ZIP format.
Unzip the downloaded file into a directory.

Q : Where Are PHP Configuration Settings Stored?
A : PHP stores configuration settings in a file called php.ini in PHP home directory. You can open it with any text editor to your settings.

Q : What Are the Special Characters You Need to Escape in Single-Quoted Stings?
A : There are two special characters you need to escape in a single-quote string: the single quote (') and the back slash (). Here is a PHP script example of single-quoted strings:

echo 'Hello world!';
echo 'It's Friday!';
echo ' represents an operator.';
?>

This script will print:
Hello world!It's Friday! represents an operator

Q : How To Convert Numbers to Strings in PHP?
A : In a string context, PHP will automatically convert any numeric value to a string. Here is a PHP script examples:

print(-1.3e3);
print(" ");
print(strlen(-1.3e3));
print(" ");
print("Price = $" . 99.99 . " ");
print(1 . " + " . 2 . " = " . 1+2 . " ");
print(1 . " + " . 2 . " = " . (1+2) . " ");
print(1 . " + " . 2 . " = 3 ");
print(" ");
?>

This script will print:

-1300
5
Price = $99.99
3
1 + 2 = 3
1 + 2 = 3

The print() function requires a string, so numeric value -1.3e3 is automatically converted to a string "-1300". The concatenation operator (.) also requires a string, so numeric value 99.99 is automatically converted to a string "99.99". Expression (1 . " + " . 2 . " = " . 1+2 . " ") is a little bit interesting. The result is "3 " because concatenation operations and addition operation are carried out from left to right. So when the addition operation is reached, we have "1 + 2 = 1"+2, which will cause the string to be converted to a value 1.

Q : How To Replace a Substring in a Given String in PHP?
A : If you know the position of a substring in a given string, you can replace that substring by another string by using the substr_replace() function. Here is a PHP script on how to use substr_replace():

$string = "Warning: System will shutdown in NN minutes!";
$pos = strpos($string, "NN");
print(substr_replace($string, "15", $pos, 2)." ");
sleep(10*60);
print(substr_replace($string, "5", $pos, 2)." ");
?>

This script will print:

Warning: System will shutdown in 15 minutes!
(10 minutes later)
Warning: System will shutdown in 5 minutes!
Like substr(), substr_replace() can take negative starting position counted from the end of the string.

Q : How To Compare Two Strings with Comparison Operators in PHP?
A : PHP supports 3 string comparison operators, <, ==, and >, that generates Boolean values. Those operators use ASCII values of characters from both strings to determine the comparison results. Here is a PHP script on how to use comparison operators:

$a = "PHP is a scripting language.";
$b = "PHP is a general-purpose language.";
if ($a > $b) {
print('$a > $b is true.'." ");
} else {
print('$a > $b is false.'." ");
}
if ($a == $b) {
print('$a == $b is true.'." ");
} else {
print('$a == $b is false.'." ");
}
if ($a < $b) {
print('$a < $b is true.'." ");
} else {
print('$a < $b is false.'." ");
}
?>

This script will print:

$a > $b is true.
$a == $b is false.
$a < $b is false.

PHP

Q : What Is a Persistent Cookie?
A : A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer. By default, cookies are created as temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:
• Temporary cookies can not be used for tracking long-term information.
• Persistent cookies can be used for tracking long-term information.
• Temporary cookies are safer because no programs other than the browser can access them.
• Persistent cookies are less secure because users can open cookie files see the cookie values.

Q : What’s the difference between include and require?
A : It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue

Q : What are the differences between GET and POST methods in form submitting, give the case where we can use GET and we can use POST methods?

Anwser 1:
When we submit a form, which has the GET method it displays pair of name/value used in the form at the address bar of the browser preceded by url. Post method doesn't display these values.

Anwser 2:
When you want to send short or small data, not containing ASCII characters, then you can use GET” Method. But for long data sending, say more then 100 character you can use POST method.

Once most important difference is when you are sending the form with GET method. You can see the output which you are sending in the address bar. Whereas if you send the form with POST” method then user can not see that information.

Anwser 3:
What are "GET" and "POST"?
GET and POST are methods used to send data to the server: With the GET method, the browser appends the data onto the URL. With the Post method, the data is sent as "standard input."

Major Difference
In simple words, in POST method data is sent by standard input (nothing shown in URL when posting while in GET method data is sent through query string.

Ex: Assume we are logging in with username and password.

GET: we are submitting a form to login.php, when we do submit or similar action, values are sent through visible query string (notice ./login.php?username=...&password=... as URL when executing the script login.php) and is retrieved by login.php by $_GET['username'] and $_GET['password'].

POST: we are submitting a form to login.php, when we do submit or similar action, values are sent through invisible standard input (notice ./login.php) and is retrieved by login.php by $_POST['username'] and $_POST['password'].

POST is assumed more secure and we can send lot more data than that of GET method is limited (they say Internet Explorer can take care of maximum 2083 character as a query string).

Anwser 4:

In the get method the data made available to the action page ( where data is received ) by the URL so data can be seen in the address bar. Not advisable if you are sending login info like password etc. In the post method the data will be available as data blocks and not as query string in case of get method.

Anwser 5:

When we submit a form, which has the GET method it pass value in the form of query string (set of name/value pair) and display along with URL. With GET we can a small data submit from the form (a set of 255 character) whereas Post method doesn't display value with URL. It passes value in the form of Object and we can submit large data from the form.

Anwser 6:
On the server side, the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.
On the browser side, the difference is that data submitted by the GET method will be displayed in the browser’s address field. Data submitted by the POST method will not be displayed anywhere on the browser.
GET method is mostly used for submitting a small amount and less sensitive data. POST method is mostly used for submitting a large amount or sensitive data

Q : How many ways can we get the value of current session id?
A : session_id() returns the session id for the current session.

Q : How can I execute a PHP script using command line?
A : Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.
Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

Q : How can we send mail using JavaScript?
A : No. There is no way to send emails directly using JavaScript.

But you can use JavaScript to execute a client side email program send the email using the "mailto" code. Here is an example:

function myfunction(form)
{
tdata=document.myform.tbox1.value;
location=" mailto:mailid@domain.com?subject =...";
return true;
}

Q : How can we create a database using PHP and mysql?
A : We can create MySQL database with the use of mysql_create_db($databaseName) to create a database.

Q : How can we submit form without a submit button?
A : We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form. For example:

Q : What is the difference between mysql_fetch_object and mysql_fetch_array?
A : MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array

Q : How can we find the number of rows in a result set using PHP?
A : Here is how can you find the number of rows in a result set in PHP:
$result = mysql_query($any_valid_sql, $database_link);
$num_rows = mysql_num_rows($result);
echo "$num_rows rows found";

Q : How many values can the SET function of MySQL take?
A : MySQL SET function can take zero or more values, but at the maximum it can take 64 values.

Q : How many values can the SET function of MySQL take?
A : MySQL SET function can take zero or more values, but at the maximum it can take 64 values.

Q : What is the difference between the functions unlink and unset?
A : unlink() is a function for file system handling. It will simply delete the file in context.
unset() is a function for variable management. It will make a variable undefined.

Q : What is the difference between CHAR and VARCHAR data types?
A : CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column. For example, "Hello!" will be stored as "Hello! " in CHAR(10) column.
VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.
How can we encrypt and decrypt a data present in a mysql table using mysql?
AES_ENCRYPT() and AES_DECRYPT()

Q : What are the difference between abstract class and interface?
A : Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.
Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

Q : How can increase the performance of MySQL select query?
A : We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.

Q : Explain the ternary conditional operator in PHP?
A : Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed

Q : What’s the difference between md5(), crc32() and sha1() crypto on PHP?
A : The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

Q : What is the functionality of MD5 function in PHP?
A : string md5(string)
It calculates the MD5 hash of a string. The hash is a 32-character hexadecimal

Q : What is the difference between htmlentities() and htmlspecialchars()?
A : htmlspecialchars() - Convert some special characters to HTML entities (Only the most widely used)
htmlentities() - Convert ALL special characters to HTML entitie

Q : How can we submit from without a submit button?
A : Trigger the JavaScript code on any event ( like onSelect of drop down list box, onfocus, etc ) document.myform.submit(); This will submit the form

Q : What is the difference between PHP4 and PHP5?
A : PHP4 cannot support oops concepts and Zend engine 1 is used.
PHP5 supports oops concepts and Zend engine 2 is used.
Error supporting is increased in PHP5.
XML and SQLLite will is increased in PHP5.

Q : What is the difference between explode and split?
Split function splits string into array by regular expression. Explode splits a string into array by string.

Q : What is difference between srand & shuffle?
The srand function seeds the random number generator with seed and shuffle is used for shuffling the array values.
shuffle - This function shuffles (randomizes the order of the elements in) an array. This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
srand - Seed the random number generator

The srand function seeds the random number generator with seed and shuffle is used for shuffling the array values.
shuffle - This function shuffles (randomizes the order of the elements in) an array. This function assigns new keys for the elements in array. It will remove any existing keys you may have assigned, rather than just reordering the keys.
srand - Seed the random number generator

Q : What are the different types of errors in PHP?
A : 1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.
2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place.

Wednesday, December 31, 2008

Recent ASP Interview Questions & Answers

Q : What’s the difference between client-side script and server-side script?
A : Scripts executed only by the browser without contacting the server is called client-side script. It is browser dependent. The scripting code is a visible to the user and hence not secure. Scripts are executed by the web server and processed by the server is called server-side script.

Q : What is Session Object?
A : Session object is stored in the information about a User’s session. Gives a notification when a user session begins or ends.

Q : What is the Server-Side includes?
Server side includes provides the extra information by which it makes the site easier to manage. It can include the text files using the #include statement, retrieve the size and last modification date of a file, defines how variables and error messages are displayed and inserts the values of HTTP variables in the page sent back to the browser.

Q : What is Response Object?
A : Response object is controls the information sent to the user. The various methods are:
Response.Write - Sends information directly to a browser
Response.Redirect - Directs a user to a URL other than the requested URL
Response.ContentType - Controls the type of content sent
Response.Cookies - Sets cookie values
Response.Buffer - To Buffer information

Q : What is a TextStream object?
A : Text Stream object allows you to access the read or write the contents of text files stored on the web server.

Q : What is Request Object?
A : Gets information from the user. It has five collections of by which values can be accessed. They are:
Querystring, Form, Cookies, Server Variables & ClientCertificate

Q : Why do we use Option Explicit?
A : Answer 1 :
Correct answer is – This statement force the declaration of variables in VB before using them.

Answer 2 :
To avoid multiple variables of the same name.

Q : What are the Web Servers supporting in ASP?
A : There are three types of web servers supporting in asp,
Internet Information Server (IIS) on Windows NT
Peer Web Services on Windows NT
Personal Web Server (PWS) on Windows 95

Q : What is asession?
A :Session is known as a user accessing an application.

Q : Explain some of the ASP components?
A : Ad Rotator component : A way to manage advertisements on the web site.
Content Linker component : A technique to direct users through a set of pages on a web site by creating a list of URLs and description of the next and previous pages.
Database Access component : Allows to access data from the database
Browser Capabilities component : Allows to customize the page to the ability of the browser viewing it.

Q : What are the advantages of using ASP?
A : Minimizes network traffic by limiting the need for the browser and server to talk to each other
Makes for quicker loading time since HTML pages are only downloaded
Can provide the client with data that does not reside on the client’s machine
Allows to run programs in languages that are not supported by the browser
Provides improved security measures since the script cannot be viewed by the brows.

Q : What is the function of Buffer in Response Object?
A : Buffer in response object controls the HTML output stream manually.

Q : What are the methods in Session Object?
A : The Session Object have only one method, which is Abandon. It destroys all the objects stored in a Session Object and releases the server resources they occupied.

Q : What is FileSystemObject object?
A : FileSystemobjaect provides access to the physical file system of the web server. It gets and manipulates the information about all drives in a server, folders and sub-folders on a drive and files inside a folder.

Q : What’s the difference between HTML and ASP?

ASP executes code on the server side whereas the browser interprets HTML.
ASP can use any of the scripting languages
Create pages that will be customized to display only things that will be of interest to a particular user
Can edit contents of a web page by updating a text file or a database rather than the HTML code itself .

Q : What are the browsers that can access ASP pages?
A: Netscape Communicator/ Navigator (supports only JavaScript, VBScript)
Internet Explorer (supports VBScript, JavaScript)

Your Ad Here