Thursday, May 5, 2011

Interview questions 20-30

21. How can we encrypt the username and password using PHP?

 1.  base64_encode() 

2. $encrypted_username=md5($username); $encrypted_password=md5($password);

   3. $encrypted_username=sha1($username);   $enncrypted_password=sha1($password); 

22. What are the features and advantages of object-oriented programming?

standardization , re-usability , flexibility , less code 

23. What are the differences between procedure-oriented languages and object-oriented languages?


In procedural programming the main emphasis is on procedure 
while in object oriented the data is important part. on the same hand data is
more secured in object oriented program.

--
Procedure Oriented Language: ----
PO Language is fully concentrates on Procedures/functions/methods.
It normally works as a
sequence of actions as seen in flowchart or in any algorithm.
It follows top-down approach. It totally focuses
on methods and not the data which is utilized by methods.
In PO languages if data is used by many methods then its declared as global data but there is a problem if we do that,
what is that, if we forgot or by mistake if we
consume that data in some other method than it comes with problem.
Mostly these scenarios happen in large systems.

Example: COBOL, PASCAL, C, FORTRAN etc.

Object Oriented Language:
---
OO concepts says it think about data and bind that data and methods those are
manipulating that data into one entity
nown as object and then utilize that object into system.
Example: C++, Java, C#, VB.Net etc.
There are some fundamental concepts of OO Language which a
language has to follow
to be a truly OO language.

OBJECT
CLASS
ABSTRACTION
ENCAPSULATION
DATA HIDING / INFORMATION HIDING
INHERITANCE
POLYMORPHISM


24. What is the use of friend function?

Friend functions
Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.
A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.
class mylinkage
{
private:
mylinkage * prev;
mylinkage * next;

protected:
friend void set_prev(mylinkage* L, mylinkage* N);
void set_next(mylinkage* L);

public:
mylinkage * succ();
mylinkage * pred();
mylinkage();
};

void mylinkage::set_next(mylinkage* L) { next = L; }

void set_prev(mylinkage * L, mylinkage * N ) { N->prev = L; }

Friends in other classes
It is possible to specify a member function of another class as a friend as follows:
class C
{
friend int B::f1();
};
class B
{
int f1();
};

It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.
class A
{
friend class B;
};

Friend functions allow binary operators to be defined which combine private data in a pair of objects. This is particularly powerful when using the operator overloading features of C++. We will return to it when we look at overloading.


25. What are the differences between public, private, protected, static, transient, final and volatile?

Public : access anyware in script 
Protected: access only same class and access inherited class

Private: access only in same class

Final: restrict overriding with child class

26. What are the different types of errors in PHP?


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 behaviour.

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 behaviour is to display them to the user when they take place.

27. What is the functionality of the function strstr and stristr?


strstr-finds the first occurence of a string inside another string (case-sensitive)
stristr-finds the first occurence of a string inside another string (case-insensitive).

28. What are the differences between PHP 3 and PHP 4 and PHP 5?

php3-functionalities are addes  php4-zend engine is added  php5-oops concepts are added

29. How can we convert asp pages to PHP pages?

Follow the steps below for converting ASP code into PHP.

In ASP, there is no need to put semicolon at the end of the each line, but a semicolon is required in PHP.

1. ASP syntax and PHP syntax

dim DescriptionText should be replaced by $ DescriptionText;

CStr(Request("section")) should be replaced by $_GET["section"]

if isnull(SectionID) or trim(SectionID) = "" then
//body
end if
in ASP is replaced by,
if($SectionID=="Null" || trim($SectionID)== "")


{
//body


}
in PHP

XMLFileName = BaseXMLPath & "about/" & SectionID & ".xml"
is replaced by,
$XMLFileName = $BaseXMLPath."about/".$SectionID.".xml";

XMLLocalFileName = Server.MapPath(XMLFileName)
In ASP Server.MapPath() function returns the physical location of the file name of an ASP file.
It returns something like this c:/apache/htdocs/foldername/filename.asp

We can use the following workaround below to get to the file location:

$root=$_SERVER['DOCUMENT_ROOT'];
$folder_file=$_SERVER['PHP_SELF'];
$filename=basename($_SERVER['PHP_SELF']);
$filepos=strpos($folder_file,$filename);
$folder=substr($folder_file,0,$filepos);
$file_location=$root.$folder;
$XMLLocalFileName=$file_location.$XMLFileName;
Now the ‘$XMLLocalFileName’ will return c:/apache/htdocs/foldername/filename.php

If you know an alternative simple solution you can share it here.

In ASP the logical operators used in conditions
are: &&-‘and’ ||- ‘or’
But in PHP it is replaced by && and ||

In ASP the array declaration is like this
Array()
In PHP it is replaced by array()

The ASP Request.ServerVariables("URL") function return folder name and filename.
In PHP its equivalent function is $_SERVER['PHP_SELF'];

In ASP the format for a function is
function functionName(argument)
//body of function
end function

In PHP the function format is:
function fuctionName(argument)

{
//body of function
}

In ASP the format for a for loop is:
for i=0 to sectionNode.length
//body of for loop
next


The PHP equivalent is:
for($i=0;$i<=count($sectionNode);$i++)


{
//body of for loop
}

In ASP Response.Write() function is used to display content in webpage and Response.End() is used to end the execution flow.
Its equivalent function used in PHP is echo and die.

In ASP Request.ServerVariables("HTTP_HOST") return the server name
Its equivalent function used in PHP is $_SERVER['HTTP_HOST']

the Request.Form() and Request.QueryString in ASP is same as $GET[‘’] and $_POST[‘’] in PHP

the instr() function return the integer value of find string in ASP, its equivalent function used in PHP is strpos()

the Int() function in ASP is replaced by intval() in PHP.

the Rnd() function in ASP is replaced by rand() in PHP

the Len() function in ASP is replaced by strlen() in PHP

The Mid() function in ASP returns a specified number of characters from a string, we used substr() function to return the same string in PHP.

the Replace() function in ASP is replaced by str_replace() in PHP .

the Trim() function in ASP is replaced by trim() in PHP.

2. Syntax for handling XML conversion.
Note that the syntax for PHP is with reference to PHP version 4 . It may be a slightly different in higher versions.


XML=load(XMLLocalFileName);
replaced by,
$XML=domxml_open_file($XMLLocalFileName);

documentElement
replaced by,
document_element()

SectionNode=RootNode->childNnodes(0);
replaced by,
$childnodes=$RootNode->child_nodes();
$SectionNode=$childnodes[1];

SectionNode->getAttribute("name");
replaced by,
$SectionNode->get_attribute("name");

DescriptionText =(DescriptionNode.text)
replaced by,
$DescriptionText =($DescriptionNode->get_content())



30. What is the functionality of the function htmlentities?


The htmlentities() function converts characters to HTML entities.
* ENT_COMPAT - Default. Encodes only double quotes
* ENT_QUOTES - Encodes double and single quotes

* ENT_NOQUOTES - Does not encode any quotes

$str = "Jane & 'Tarzan'";

echo htmlentities($str, ENT_COMPAT);



echo htmlentities($str, ENT_QUOTES);

echo htmlentities($str, ENT_NOQUOTES);
?>
the output

Jane & 'Tarzan'
Jane & 'Tarzan'

Jane & 'Tarzan'

PHP Interview Questions 10-20


11. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?


MyISAM: This is default. Based on Indexed Sequntial Access 

ISAM : same
HEAP : Fast data access, but will loose data if there is a
crash. Cannot have BLOB, TEXT & AUTO INCRIMENT fields
InoDB : same as BDB
Merge : Supports Transactions using
The above create query mysql will create MYISAM table.

12. Functions in IMAP, POP3 AND LDAP?

Imap functions:

imap_8bit — Convert an 8bit string to a quoted-printable string

imap_alerts — Returns all IMAP alert messages that have occurred

imap_append — Append a string message to a specified mailbox

imap_base64 — Decode BASE64 encoded text

imap_binary — Convert an 8bit string to a base64 string

imap_body — Read the message body

imap_bodystruct — Read the structure of a specified body section of a specific message

imap_check — Check current mailbox

imap_clearflag_full — Clears flags on messages

imap_close — Close an IMAP stream

imap_createmailbox — Create a new mailbox

imap_delete — Mark a message for deletion from current mailbox

imap_deletemailbox — Delete a mailbox

imap_errors — Returns all of the IMAP errors that have occured

imap_expunge — Delete all messages marked for deletion

imap_fetch_overview — Read an overview of the information in the headers of the given message

imap_fetchbody — Fetch a particular section of the body of the message

imap_fetchheader — Returns header for a message

imap_fetchmime — Fetch MIME headers for a particular section of the message

imap_fetchstructure — Read the structure of a particular message

imap_gc — Clears IMAP cache

imap_get_quota — Retrieve the quota level settings, and usage statics per mailbox

imap_get_quotaroot — Retrieve the quota settings per user

imap_getacl — Gets the ACL for a given mailbox

imap_getmailboxes — Read the list of mailboxes, returning detailed information on each one

imap_getsubscribed — List all the subscribed mailboxes

imap_header — Alias of imap_headerinfo

imap_headerinfo — Read the header of the message

imap_headers — Returns headers for all messages in a mailbox

imap_last_error — Gets the last IMAP error that occurred during this page request

imap_list — Read the list of mailboxes

imap_listmailbox — Alias of imap_list

imap_listscan — Returns the list of mailboxes that matches the given text

imap_listsubscribed — Alias of imap_lsub

imap_lsub — List all the subscribed mailboxes

imap_mail_compose — Create a MIME message based on given envelope and body sections

imap_mail_copy — Copy specified messages to a mailbox

imap_mail_move — Move specified messages to a mailbox

imap_mail — Send an email message

imap_mailboxmsginfo — Get information about the current mailbox

imap_mime_header_decode — Decode MIME header elements

imap_msgno — Gets the message sequence number for the given UID

imap_num_msg — Gets the number of messages in the current mailbox

imap_num_recent — Gets the number of recent messages in current mailbox

imap_open — Open an IMAP stream to a mailbox

imap_ping — Check if the IMAP stream is still active

imap_qprint — Convert a quoted-printable string to an 8 bit string

imap_renamemailbox — Rename an old mailbox to new mailbox

imap_reopen — Reopen IMAP stream to new mailbox

imap_rfc822_parse_adrlist — Parses an address string

imap_rfc822_parse_headers — Parse mail headers from a string

imap_rfc822_write_address — Returns a properly formatted email address given the mailbox, host, and personal info

imap_savebody — Save a specific body section to a file

imap_scanmailbox — Alias of imap_listscan

imap_search — This function returns an array of messages matching the given search criteria

imap_set_quota — Sets a quota for a given mailbox

imap_setacl — Sets the ACL for a giving mailbox

imap_setflag_full — Sets flags on messages

imap_sort — Gets and sort messages

imap_status — Returns status information on a mailbox

imap_subscribe — Subscribe to a mailbox

imap_thread — Returns a tree of threaded message

imap_timeout — Set or fetch imap timeout

imap_uid — This function returns the UID for the given message sequence number

imap_undelete — Unmark the message which is marked deleted

imap_unsubscribe — Unsubscribe from a mailbox

imap_utf7_decode — Decodes a modified UTF-7 encoded string

imap_utf7_encode — Converts ISO-8859-1 string to modified UTF-7 text

imap_utf8 — Converts MIME-encoded text to UTF-8

LDAP Functions:

ldap_8859_to_t61 — Translate 8859 characters to t61 characters

ldap_add — Add entries to LDAP directory

ldap_bind — Bind to LDAP directory

ldap_close — Alias of ldap_unbind

ldap_compare — Compare value of attribute found in entry specified with DN

ldap_connect — Connect to an LDAP server

ldap_count_entries — Count the number of entries in a search

ldap_delete — Delete an entry from a directory

ldap_dn2ufn — Convert DN to User Friendly Naming format

ldap_err2str — Convert LDAP error number into string error message

ldap_errno — Return the LDAP error number of the last LDAP command

ldap_error — Return the LDAP error message of the last LDAP command

ldap_explode_dn — Splits DN into its component parts

ldap_first_attribute — Return first attribute

ldap_first_entry — Return first result id

ldap_first_reference — Return first reference

ldap_free_result — Free result memory

ldap_get_attributes — Get attributes from a search result entry

ldap_get_dn — Get the DN of a result entry

ldap_get_entries — Get all result entries

ldap_get_option — Get the current value for given option

ldap_get_values_len — Get all binary values from a result entry

ldap_get_values — Get all values from a result entry

ldap_list — Single-level search

ldap_mod_add — Add attribute values to current attributes

ldap_mod_del — Delete attribute values from current attributes

ldap_mod_replace — Replace attribute values with new ones

ldap_modify — Modify an LDAP entry

ldap_next_attribute — Get the next attribute in result

ldap_next_entry — Get next result entry

ldap_next_reference — Get next reference

ldap_parse_reference — Extract information from reference entry

ldap_parse_result — Extract information from result

ldap_read — Read an entry

ldap_rename — Modify the name of an entry

ldap_sasl_bind — Bind to LDAP directory using SASL

ldap_search — Search LDAP tree

ldap_set_option — Set the value of the given option

ldap_set_rebind_proc — Set a callback function to do re-binds on referral chasing

ldap_sort — Sort LDAP result entries

ldap_start_tls — Start TLS

ldap_t61_to_8859 — Translate t61 characters to 8859 characters

ldap_unbind — Unbind from LDAP directory

13. How can I execute a PHP script using command line?


Prompt > php file_path/siva.php


14. Suppose your Zend engine supports the mode Then how can u configure your PHP Zend engine to support mode ?


In the php.ini file you can change the value of short_open_tag = on     into   short_open_tag = off 

15. Shopping cart online validation i.e. how can we configure Paypal, etc.?

        first we have to create a test marchentaccount in paypal touse that in test modein

shopping cart we have to put every items in the cokie, we can use the session also but
good to go with cookie.in test mode basically we are giving some information and the price,
the currency type and post the form to paypal.

just an example :
you have to cretate this form dynamicallyand have to post it to the sandbox.paypal
for test mode and if you will go for lkive you have to post the for to paypaldirectly

'<'form name="xxx"action="https://www.sandbox.paypal.com/cgi-bin/webscr"method="post">

'<'input type="hidden" name="cmd" value="_xclick">
'<'input type="hidden" name="business" value="'<'?php echo$MARCHENT_ID;?>">
'<'input type="hidden" name="item_name" value="'<'?php echo $ORDER_REQUEST;?>">

'<'input type="hidden" name="item_number" value="5">
'<'input type="hidden" name="'<'?php echo $item_name;?>" value="'<'?php echo $rst['title'];?>">
'<'input type="hidden" name="'<'?php echo $amount;?>"value="'<'?php echo $rate*$rst['cost'];?>">
'<'input type="hidden" name="currency_code" value="GBP">
'<'input type="hidden" name="return" value="'<'?php echo $RETURN_ADDRESS;?>">
'<'input type="hidden"name="cpp_header_image" value="'<'?php echo $HEADERIMAGE;?>">
'<'input type="hidden" name="cancel_return" value="'<'?php echo $CANCEL_RETURN;?>">
'