Tuesday, November 6, 2007

PHP Interview Questions

Here is some PHP Interview Questions, that will helpfull to PHP Interview Candidates

1. What is CAPTCHA?

CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans Apart. To prevent spammers from using bots to automatically fill out forms, CAPTCHA programmers will generate an image containing distorted images of a string of numbers and letters. Computers cannot determine what the numbers and letters are from the image but humans have great pattern recognition abilities and will be able to fairly accurately determine the string of numbers and letters. By entering the numbers and letters from the image in the validation field, the application can be fairly assured that there is a human client using it. To read more look here:
http://en.wikipedia.org/wiki/Captcha


2. What is difference between require_once(), require(), include().
Becouse above three function usely use to call a file in another file?

Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error. Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING. There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().


3. If you have to work with dates in the following format: "Tuesday, February 14, 2006 @ 10:39 am", how can you convert them to another format, that is easier to use?

The strtotime function can convert a string to a timestamp. A timestamp can be converted to date format. So it is best to store the dates as timestamp in the database, and just output them in the format you like.

So let's say we have
$date = "Tuesday, February 14, 2006 @ 10:39 am";
In order to convert that to a timestamp, we need to get rid of the "@" sign, and we can use the remaining string as a parameter for the strtotime function.

So we have
$date = str_replace("@ ","",$date);
$date = strtotime($date);

now $date is a timestamp
and we can say:

echo date("d M Y",$date);


4. How we know browser properties?

get_browser() attempts to determine the capabilities of the user's browser. This is done by looking up the browser's information in the browscap.ini file.

echo $_SERVER['HTTP_USER_AGENT'] . "

\n";

$browser = get_browser();

foreach ($browser as $name => $value) {
echo "$name $value
\n";
}


5. How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)?

For this we can use the session objec($_SESSION)t. When the user login with his/ her user name and password, usually we check those to ensure for correctness. If that user name and password are valid one then we can store that user name in a session and then we can very that session variable has been set or not in a single files and we can include that file in all pages.

6. How i can get ip address?

We can use SERVER var $_SERVER['SERVER_ADDR'] and getenv("REMOTE_ADDR") functions to get the IP address.

7. What is differenc between mysql_connect and mysql_pconnec?

mysql_pconnect establishes a persistent connection. If you don't need one (such as a website that is mostly HTML files or PHP files that don't call the db) then you don't need to use it. mysql_connect establishes a connection for the duration of the script that access the db. Once the script has finished executing it closes the connection. The only time you need to close the connection manually is if you jump out of the script for any reason.

If you do use mysql_pconnect. You only need to call it once for the session. That's the beauty of it. It will hold open a connection to the db that you can use over and over again simply by calling the resource ID whenever you need to interact with the db.

8. What is the difference between echo and print statement?

There is a slight difference between print and echo which would depend on how you want to use the outcome. Using the print method can return a true/false value. This may be helpful during a script execution of somesort. Echo does not return a value, but has been considered as a faster executed command. All this can get into a rather complicated discussion, so for now, you can just use whichever one you prefer.

9. How to make a download page in own site, which i can know that how many file has been loaded by particular user or particular ipaddress?

We can use hyperlink having URL where file are kept. and we only allow regisetered user to download. from session of user we can get the user detail

28 comments:

Satheesh said...

Hi this article is useful for me thanks


Satheesh
semsaz.com
php/mysql interview questions and answers

atomicarena said...

Thanks,
it was helpful
Praveen

Kripssmart said...

Nice one! Could have added some more.

Thanks!

Jayesh Wadhwani said...

For question 8 "Difference between echo & print please the correct answer:phptouch.com

John said...

Hi, This article helped me a lot.
Thanks.
Also folks, there are some good questions in
http://www.phpinterviewquestions.com

Cheers !

Saira said...

thanx alot for sharring :)

Saira said...
This comment has been removed by the author.
free tutorials said...

Hey thanks a lot for sharing useful interview questions..... which will be very helpful while attending the interviews.....
glad i found ur site...really a very helpful site.....
by the way check out my collection of php interview questions from here: php interview questions

bologna03 said...

Hi

Tks very much for post:

I like it and hope that you continue posting.

Let me show other source that may be good for community.

Source: Sample interview questions

Best rgs
David

sanjay said...

should be add more question like this because no more of face the interview .

Tutorials and interview questions said...

Hey thanks a lot for sharing the information.. check out my collection of php interview questions from the below link:

php interview questions

job interviews said...

A interview plays a major role in your professional life. It is recommend that a candidate must know each and every interview strategy. It will helps you in interview.

Anonymous said...

very nice questions and their answers. please can u upload latest php questions

taver said...

Hi

I read this post two times.

I like it so much, please try to keep posting.

Let me introduce other material that may be good for our community.

Source: Web interview questions

Best regards
Henry

Nilanjan Maity said...

The difference between echo and print function is not clear....other all is fine

php institute in Chandigarh said...

Really nice blog..Thanks for sharing nice discussion about php questions..These questions very helpful for interview....Thanks a lot.......

Brain Damaged said...

I'm sorry but these questions are nigh useless in my actual interviews. They are just trivia questions and shows you nothing about a candidates engineering skills and code quality.

For me I prefer longer questions that asks the candidate to build a simple software from a set of specifications. These are meant to show us the candidate's critical thinking skills, code quality and engineering skills.

wisdom said...

Thanks for the post. I need more basic questions to face interview.

Thanks.

Anonymous said...

thnx,this is really usefull

andrew siddle said...
This comment has been removed by the author.
andrew siddle said...

thanks for the information about Captcha Code..

raman said...

nice man

Classifieds php said...

Thanks for sharing this great content, I really enjoyed the insign you bring to the topic, awesome stuff!

Classifieds php

andrew siddle said...

Thanks for sharing these question.
Captcha Code

Anonymous said...

THanks, these are some really good ones!

More here:

PHP interview questions for freshers

sultan said...

packers and movers
packers and movers lucknow
packers and movers ghaziabad
packers and movers noida
packers and movers delhi
packers and movers hyderabad
packers and movers chandigarh
packers and movers raipur
packers and movers kolkata
packers and movers kolkata
packers and movers gurgaon
packers and movers bangalore
packers and movers mumbai
packers and movers ranchi
packers and movers chennai
packers and movers pune
packers and movers faridabad
packers and movers jaipur
packers and movers ahmedabad

yaseen khan said...
This comment has been removed by the author.
karunakar2093 said...

thank for sharing. it is vary useful for freshers ......php interview question and answers