Interview Questions and Answers for Freshers

February 16th, 2013 by Laeeq | No comments

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”

echo $_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.

$_SESSION['USERNAME']=”phpzag”;

Now we get the data from our session:

$session_data=$_SESSION['USERNAME'];

Q- If cookies are disabled will the sessions work? Why?

Session will work if cokkies are disabled. If cookie is enabled on client machine then php will use cookies to handle sessions else if cookie is disabled on client machine check is made to ensure that if php5 is configured with

–enable-trans-sid and
–enable-track-vars option.

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.

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • Wrapping Text using PHP
  • PHP 5.5 beta 4 is now available
  • Swapping Array Keys and Values
  • PHP Security
  • Working with Image Metadata in PHP
  • Converting Between Relative and Absolute File Path
  • Parsing File Paths with PHP
  • How to remove HTML Comments with PHP?
  • How to access .htaccess values?
  • Dealing With Common PHP Errors
  • Display numbers with ordinal suffix using PHP
  • Function to set COLLATION on database fields of Mysql
  • Read and write to remote files using PHP
  • Sharing PHP SESSION Variables between Multiple Subdomains
  • PHP 5.5.0 Alpha4 Development Preview Released
  • Check a string starts with http using PHP
  • Cross-Site Scripting Attacks (XSS)
  • PHP 5.4.11 and PHP 5.3.21 released!
  • PHP Memory Leak Issue
  • PHP 5.5.0 Alpha3 released
  •  

     

    1. No comments yet.
    1. No trackbacks yet.