php interview questions

Difference between Cookies and Session in PHP

  • Cookies are stored in the user’s browser memory.A cookie can keep information in the user’s browser until deleted.
  • Session : logical object that allows you to preserve data across subsequent http requests.Whenever PHP creates a new session, it generates a session ID.
  • Session values are store in server side not in user’s machine. A session is available as long as the browser is opened. User couldn’t be disabled the session.
  • Cookies are stored in client side and sessions are stored in server side.
  • Cookies can only store strings.We could store not only strings but also objects in session.
  • we could be save cookie for future reference, but session couldn’t. When users close their browser, they also lost the session.
  • Cookies can not hold multiple variables,But Session can hold multiple variables.
  • We can set expiry for a cookie,The session only remains active as long as the browser is open.
  1. How we can retrieve the data in the result set of MySQL using PHP?
    • 1. mysql_fetch_row
    • 2. mysql_fetch_array
    • 3. mysql_fetch_object
    • 4. mysql_fetch_assoc
  2. What is the use of explode() function ?Syntax : array explode ( string $delimiter , string $string [, int $limit ] );
    This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.
  3. What is the difference between explode() and split() functions?Split function splits string into array by regular expression. Explode splits a string into array by string.
  4. What is the use of mysql_real_escape_string() function?It is used to escapes special characters in a string for use in an SQL statement.
  5. What is the use of header() function in php ?
    The header() function sends a raw HTTP header to a client browser.Remember that this function must be called before sending the actual out put.For example, You do not print any HTML element before using this function.
  6. what is the use of isset() in php?
    This function is used to determine if a variable is set and is not NULL
  7. Function of htmlentities : The htmlentities() function converts characters to HTML entities.
  8. Echo vs. print statement.

    echo() and print() are language constructs in PHP, both are used to output strings. The speed of both statements is almost the same.

    echo() can take multiple expressions whereas print cannot take multiple expressions.

    Print return true or false based on success or failure whereas echo doesn’t return true or false.

  9. What are the different types of errors in php?

    E_ERROR: A fatal error that causes script termination
    E_WARNING: Run-time warning that does not cause script termination
    E_PARSE: Compile time parse error.
    E_NOTICE: Run time notice caused due to error in code
    E_CORE_ERROR: Fatal errors that occur during PHP’s initial startup (installation)
    E_CORE_WARNING: Warnings that occur during PHP’s initial startup
    E_COMPILE_ERROR: Fatal compile-time errors indication problem with script.
    E_USER_ERROR: User-generated error message.
    E_USER_WARNING: User-generated warning message.
    E_USER_NOTICE: User-generated notice message.
    E_STRICT: Run-time notices.
    E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
    E_ALL: Catches all errors and warnings

  10. How can we register the variables into a session?

    We can use the session_register ($ur_session_var) function.

  11. What is the maximum length of a table name, database name, and fieldname in mysql?

    Database name- 64 ,Table name -64, Fieldname-64, mysql will take maximum 64 values.

  12. How To Get the Uploaded File Information in the Receiving Script?

    Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES.

    $_FILES[$fieldName][‘name’] – The Original file name on the browser system.
    $_FILES[$fieldName][‘type’] – The file type determined by the browser.
    $_FILES[$fieldName][‘size’] – The Number of bytes of the file content.
    $_FILES[$fieldName][‘error’] – The error code associated with this file upload.
    $_FILES[$fieldName][‘tmp_name’] – The temporary filename of the file in which the uploaded file was stored on the server.

  13. Difference between Persistent Cookie and Temporary cookie?

    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

  14. What is the difference between CHAR and VARCHAR data types?

    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.

    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.

Posted in php
One comment on “php interview questions
  1. cakchefq says:

    Upon the race after a long facts nhlcnieqy facts hemp http://resimlog.com/profile/casievwrig (in accordance with the principles of.

Leave a comment