Interview Questions and Answers for Freshers
Here are common questions with answer that every fresher PHP programmer is expected to know, I will add few more questions with answers in coming days.
Q- What is the difference between include and require
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.
Q- What is the difference between Session and Cookie
Sessions are stored in the server side whereas cookies are stored in the client side.
Q- How do you create a cookie, add data to it, and remove data from a cookie
Here we have created cookie “username” and assign value “phpzag” with expiration duration of 10 seconds to the timestamp.
setcookie(‘username’, ‘phpzag’, time()+10);
Now we get value of cookie “username”
Now we remove the data of cokie. When deleting a cookie you should assure that the expiration date is in the past. Examples follow show how to delete cookies sent in previous example:
setcookie (“username”, “”, time() – 10);
Q- How do you create a session, add data to a session and remove data from a session
First we start session by inintialzing session_start();
Now we will create session “USERNAME” and add data to our created session.
Now we get the data from our session:
Q- If cookies are disabled will the sessions work? Why?
If yes then php will pass session id using post method automatically and we do not need to worry about it. we just have to use sesssion functions regularly. If No then we can pass session id using SID.
Q- What is the difference between $var and $$var
$var is a variable and $$variable is a Reference or Dynamic variable.