Showing posts with label Php Interview Questions. Show all posts
Showing posts with label Php Interview Questions. Show all posts

Top PHP Interview Questions with Answers For Job


  What is PHP?

    PHP is a server side scripting language  used for web development applications.
    Php is the powerful tool for making dynamic website.
    Many open source, free and commercial scripts    and   Stuff made by php

 What is a data type?

A Data type is the classification of data into a category according to its attributes;
• Alphanumericcharacters are classified as strings
• Whole numbersare classified integers
• Numberswith decimal pointsare classified as floating points.
• True or falsevalues are classified as Boolean.
PHP is a loosely typed language;it does not have explicit defined data types.






What is a variable?

A variable is a name given to a memory location that stores data at runtime.
 The scope of a variable determines its visibility.
A global variable is accessible to all the scripts in an
application. A local variable is only accessible to the script
that it was defined in.

How to retrieve a secure URL?
To retrieve secure URLs, the cURL extension needs access to an SSL library, such as OpenSSL.
<?php
$c = curl_init('https://secure.example.com/accountbalance.php');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
 $page = curl_exec($c); curl_close($c);
?>



Why you should use variables?

Variables help separate data from the program algorithms. The same algorithm can be used
for different input data values. For example, suppose that you are developing a calculator
program that adds up two numbers, you can create two variables that accept the numbers
then you use the variables names in the expression that does the addition.


  How to show all PHP runtime errors?
 
   Add error_reporting function set  1 .

  What is htaccess?

   .htaccess files are configuration files of Apache Server which provide
   a way to make configuration changes on a per-directory basis.

How to redirect a user to a page?

header('Location: http://www.example.com/');
The redirect URL must include the protocol and hostname.




   What is  echo in php?

    It is a keyword.
    It is used to print  data on the webpage, like that <?php echo 'test'; ?> ,
  
    How to include a file to a php page?

    Add include a file using include() or require() function with the path.


    What's the difference between include and require?

    PHP provides two constructs to load code and HTML from another module: require and include.
    They both load a file as the PHP script runs, work in conditionals and loops, and complain if
    the file being loaded can't be found. The main difference is that attempting to require a
   nonexistent file is a fatal error, while attempting to include such a file produces a warning
    but does not stop script execution.

    If the file is not found by require(), it will gives a fatal error and stop the execution of the script.
    If the file is not found by include(), it  will gives a warning , but execution will continue.

    will not get the "function re-declared" error.
   
    Differences between GET and POST methods ?
    A GET request encodes the form parameters in the URL, in what is called a query string:

    /path/to/chunkify.php?word=despicable&length=3
    A POST request passes the form parameters in the body of the HTTP request, leaving the URL untouched.
    POST requests are not idempotent. This means that they cannot be cached,
    and the server is recontacted every time the page is displayed.

    How to declare an array php?

    Example : var $arr = array('ie', 'firefox', 'safari');

    What is the use of 'print' in php?

    This is not actually a real function, It is a language construct.
    So you can use with out parentheses with its argument list.
   


    What is  in_array() function?

    The in_array( ) function returns true or false, depending on whether the first
     argument is an element in the array given as the second argument.
    in_array used to checks if a value exists in an array that Searching for Values of array.
   
    What is count() function in php ?

    The count( ) and sizeof( ) functions are identical in use and effect.
    They return the number of elements in the array.


    What’s the difference between include and require?

    It’s how they handle failures. If the file is not found by require(),
   it will cause a fatal error and halt the execution of the script. If the file is not
   found by include(), a warning will be issued, but execution will continue.


    What is the difference between Session and Cookie?

    sessions are stored on the server, and cookies are stored on the client’s computers in the text file format.
    A cookie is a bit of information that the server can give to a client.
    Every session has a data store associated with it. You can register variables to be loaded
    from the data store when each page starts and saved back to the data store when the page ends.
   

   How to set cookies in PHP?

    Setcookie("test", "sem", time()+3600);
   

    How to Retrieve a Cookie Value?
     echo $_COOKIE["test"];
   

    How to create a session? 

    Create session by  session_start();

   How to set a value in session ?

    Set value into session by  $_SESSION['test_ID']=1987654;

   How to Remove data from a session?

   Remove data from  session -> session_unset($_SESSION['test_ID'];



    How to create a mysql connection?
    call mysql_connect(servername,username,password);


    How to select a database?

    call mysql_select_db($db_name);

    How to execute an sql query? How to fetch its result ?
    $my_qry = mysql_query("SELECT * FROM `test` WHERE `test_id`='16'; ");
    $result = mysql_fetch_array($my_qry);
    echo $result['First_test_name'];


    How to get the resultset of MySQL using PHP?
        1. mysql_fetch_row
        2. mysql_fetch_array
        3. mysql_fetch_object
        4. mysql_fetch_assoc
   
       
   
    How to strip whitespace or other characters from the beginning and end of a string ?

    The trim() function removes whitespaces or other predefined characters from both sides of a string.
   
    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.
   
    How to redirect a page in php?

    The following code can be add for it, header("Location:test.php");
   
    How stop the execution of a php scrip ?

    exit() function  stop the execution of a page.
   
   
    How to get the length of a string?

    strlen() function  gives  the length of a string


    How to generate random numbers in php?

    Add rand function  to generate random numbers.

    How  to varify a variable in php?

    This is_set  function is used to determine if a variable is set and is not .   

      
    What is mean by an associative array?

    Associative arrays are arrays that indexed by string keys is called associative arrays.


   
   
    How do you define a constant?

    Using define() directive, like  that define ("MYCONSTANT",765754);
   
   
    How send email using php?

    To send email using PHP, you use the mail() function.This mail() function accepts 5 parameters

    How to find current date and time?

    The date() function gives  the current date and time .
  
       
    What is the use of ksort in php?

    Its  sort an array by key in reverse order.
  
  Who is the father of PHP ?

  Rasmus Lerdorf is known as the father of PHP.     
       
    How to delete a file from the system?

    Unlink() deletes the  file from the file system.
   
    How to get the value of current session id?

    session_id() function gives the session id for the current session.


What is the difference between $name and $$name?

$name is variable where as $$name is reference variable
like $name=sonia and $$name=singh so $sonia value is singh.

  mysql_fetch_object vs  mysql_fetch_array?

mysql_fetch_object() is similar tomysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets numbers are illegal property names

In PHP for pdf which library used?. 

The PDF functions in PHP can create PDF files using the PDFlib library With version 6, PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4. There is also the » Panda module. FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs. FPDF requires no extension (except zlib to activate compression and GD for GIF support) and works with PHP4 and PHP5.
 
How  to Connecting two Strings? 
a useful concept—concatenation. It refers to the process of linking
items together. Specifically in programming, you concatenate strings.
The period . is the operator for performing this action, and it's used like so:

$tString = $String1 . $bString2;

echo $tString;





Why we use strstr?
strstr returns all of string after the first occurrence of substring .
If substring doesn't exist in string , the function returns FALSE.

How to  capitalize only the first character of a string?
you use ucfirst:
$txt = "welcome to the this site";
echo $ucfirst($txt);
 
What three components need to create a dynamic web page? 
A web server, a server-side programming language, and a database.

What does Apache use to load extensions?

Modules.

What does the PHP Interpreter do?
 It processes the HTML and PHP files.

What's a more secure function than md5() for encoding passwords? 
The sh1() function creates a 160-bit key instead of md5()'s 128-bit string. 
It also uses a superior algorithm for making it difficult to determine the 
values that generate a particular encoding.

What are the advantages of using PEAR?
 The PEAR functions are more compact, and they automate some of the manual
 work of connecting to and selecting from the database. Because PEAR code
 is used by many developers, it is less likely to have an error than to have code
 that's written from scratch.

Learn Php Code
 
PHP Functions
Php tutorial - imagemagick
php.ini Basics
PHP Sessions
Cookies Versus Sessions
PHP Web-Related Variables
PHP ERRORS
maximum size of a file uploaded
Php Image upload
php file_get_contents
MySQL Data on the Web
What are GET and POST
php and pdf
$_ENV and $_SERVER
PEAR with php
SELECTING DATA PHP
prevent hijacking with PHP
LAMP
PHP MySQL Functions
PHP Zip File Functions
Substrings PHP
PHP Variable names
PHP magic methods
How to get current session id
Add variables into a session
$_GET , $_POST,$_COOKIE
different tables present in mysql
PHP CURL
php Sessions page
PHP-sorting an array
PHP-count the elements of array
Operators for If/Else Statements
PHP file uploading code
PHP global variables
Testing working using phpinfo
PHP Code for a Valid Number
PHP-Associative Arrays
PHP mvc tutorial
PHP get_meta_tags-Extracts
difference between print and echo
PHP best tutorial-PHP variables
Reading DOC file in PHP
PHP interview questions
convert time PHP
PHP implode array elements
header function-PHP
PHP-Renaming Files Directories
PHP Classes
in_array function in PHP
keep your session secure PHP
Web Application with PHP
What is SQL Injection
PHP-extract part of a string
PHP urlencode
PHP- know browser properties
PHP- Extracting Substrings
Checking Variable Values /Types
PHP-best 20 Open Source cms
IP AddressPHP
PHP-Scope Resolution Operator
how create new instance of object
how eliminate an object
PHP- ob_start
XML file using the DOM API
PHP- MVC
PHP- CAPTCHA
PHP- Position of a Value in an Array
PHP-Mail Functions
PHP-difference include vs require
calculate the sum of values in an array
PHP-total number of rows
Show unique records mysql
MySQL Triggers
MySQL data directory
MySQL Subqueries
PHP- Networking Functions
PHP- Operators
Restore database
Conditional Functions mysql
PHP-function overloading
Friend function
mysql_connect /mysql_pconnect
PHP-Error Control Operators
what is IMAP
Apache-Specific Functions
Send Email from a PHP Script
SQL inherently
WAMP, MAMP, LAMP
Php tutorial-SYMBOLS
Table Types-MySQL
PHP-Encryption data management
PHP Array
Running MySQL on Windows
Maximum Performance MySQL
XML-RPC
PHP-static variables
Advanced Database Techniques
FTP
Codeigniter
Apache Pool Size
Why NoSQL
MySQL Server Performance
Database software
SQL Interview Answers
PHP Redirect
PHP Interview Questions with Answers
Advanced PHP

PHP INTERFACES


Class inheritanceenables you to describe a parent-child relationship
between classes. For example, you might have a base class
 Shapefrom which both Squareand Circlederive. However,
 you might often want to add additional “interfaces” to classes,
 basically meaning additional
 contracts to which
the class must adhere. This is achieved in C++ by using multiple
 inheritance and deriving from two classes. PHP chose interfaces
 as an alternative to multiple inheritance, which allows you to specify
 additional contracts a class must follow. An interface is declared
similar to a class but only includes function prototypes without
implementation and constants. Any class that “implements”
 this interface automatically has the interface’s constants defined and,
as the implementing class, needs to supply the function definitions for the
interface’s function prototypes that are all abstractmethods unless you
declare the implementing class as abstract.

abstract class Shape {
function setCenter($x, $y) {
$this->x = $x;
$this->y = $y;
}
abstract function draw();

protected $x, $y;
}
class Square extends Shape {
function draw()
{
// Here goes the code which draws the Square
...
}
}
class Circle extends Shape {
function draw()
{
// Here goes the code which draws the Circle
...
}
}
You can see that the draw()abstract method does not
 contain any code.

To implement an interface, use the following syntax:
class A implements B, C, ... {
...
}

Classes that implement an interface have an instance of a relationship
 with the interface; for example, if class Aimplements interface
 myInterface, the following results in '$obj is-A myInterface'printing:

$obj = new A();
if ($obj instanceof myInterface) {
print '$obj is-A myInterface';
}

Static Methods-PHP

 PHP supports declaring methods as static.
Whatthis means is that your static methods are part of the
 class and are not bound to any specific object instance and
 its properties. Therefore, $this isn’t accessible in these methods,
 but the class itself is by using selfto access it. Because
static methods aren’t bound to any specific object, you can
 call them without creating an object instance by using the
class_name::method()syntax. You may also call them from an
 object instance using $this->method(), but $thiswon’t
be defined in the called method. For clarity, you should use self::method()
instead of $this->method().

class PrettyPrinter {
static function printHelloWorld()
{
print "Hello, World";
self::printNewline();
}
static function printNewline()
{
print "\n";
}
}
PrettyPrinter::printHelloWorld();

The example prints the string "Hello, World"followed by a newline.
Although it is a useless example, you can see that printHelloWorld()can be
called on the class without creating an object instance using the class name,
and the static method itself can call another static method of the
class printNewline()using the self::notation. You may call a parent’s
 static method by using the parent::notation.

Static Properties

As you know by now, classes can declare properties. Each instance of the
class,object has its own copy of these properties. However, a class can
also contain static properties. Unlike regular properties, these belong to
the class itself and not to any instance of it.

class propertiesas opposed to object or instance properties. You can also
think of static properties as global variables that sit inside a class but are
accessible from anywhere via the class.
Static properties are defined by using the static keyword:
class MyClass {
static $myStaticVariable;
static $myInitializedStaticVariable = 0;
}
To access static properties, you have to qualify the property name with
the class it sits in

MyClass::$myInitializedStaticVariable++;
print MyClass::$myInitializedStaticVariable;

configuring PHP-impact security

The primary mechanism for configuring PHP is the php.inifile.
As the master file, this provides you with control over all configuration settings.
Entries generally take the format:
setting= value

Be sure to read the comments provided in the file before making changes, though.
There are a few tricks, such as include_pathusing a colon (:) as a seperator on
Unix, and a semicolon (;) on Windows.
Most Web hosts will not provide you access to your php.inifile unless you have
root access to the system (which is typically not the case if you’re using a cheap
virtual hosting service). Your next alternative is to use .htaccessfiles to configure
PHP assuming the Web server is Apache.
An .htaccessfile is a plain text file that you place in a public Web directory to
determine the behavior of Apache when it comes to serving pages from that directory; for instance, you might identify which pages you’ll allow public access to.
Note that the effect of an .htaccessfile is recursive—it applies to subdirectories
as well.

To configure PHP with .htaccessfiles, your hosting provider must have the
Apache setting AllowOverride Optionsor AllowOverride Allapplied to your
Web directory in Apache’s main httpd.confconfiguration file. Assuming that
is done, there are two Apache directives you can use to modify PHP’s configuration:
php_flag
used for settings that have boolean values (i.e. on/offor 1/0) such as
register_globals

php_value
used to specify a string value for settings, such as you might have with the
include_pathsetting
Here’s an example .htaccessfile:

# Switch off register globals
php_flag register_globals off
# Set the include path
php_value include_path ".;/home/username/pear"

The final mechanism controlling PHP’s configuration is the group of functions
ini_setand ini_alter, which let you modify configuration settings, as well as
ini_get, which allows you to check configuration settings, and ini_restore,
which resets PHP’s configuration to the default value as defined by php.iniand
any .htaccessfiles. Using ini_set, here’s an example which allows us to avoid
having to define our host, user name and password when connecting to MySQL:
ini_set('mysql.default_host', 'localhost');
ini_set('mysql.default_user', 'harryf');
ini_set('mysql.default_password', 'secret');
if (!mysql_connect()) {
echo mysql_error();
} else {
echo 'Success';
}

Be aware that PHP provides for some settings, such as error_reporting, alternative functions that perform effectively the same job as ini_set.

PHP-script-Related Variables



PHP-script Related Variables

PHP automatically creates variables for all the data it receives in an HTTP request. This can include GET data, POST data, cookie data, and environment variables. The variables are either in PHP's global symbol table or in one of a number of superglobal arrays, depending on the value of the register_globals setting in your php.ini file.
In PHP 4.2.0 and after, the default setting for register_globals is off. With register_globals off, all the various variables that are usually available directly in the global symbol table are now available via individual superglobal arrays. There is a limited set of superglobals and they cannot be created from a user-level script. The superglobal array to use depends on the source of the variable. Here is the list:
$_GET
GET-method variables. These are the variables supplied directly in the URL. For example, with http://www.example.com/script.php?a=1&b=2, $_GET['a'] and $_GET['b'] are set to 1 and 2, respectively.
$_POST
POST-method variables. Form field data from regular POST-method forms.
$_COOKIE
Any cookies the browser sends end up in this array. The name of the cookie is the key and the cookie value becomes the array value.
$_REQUEST
This array contains all of these variables (i.e., GET, POST, and cookie). If a variable appears in multiple sources, the order in which they are imported into $_REQUEST is given by the setting of the variables_order php.ini directive. The default is 'GPC', which means GET-method variables are imported first, then POST-method variables (overriding any GET-method variables of the same name), and finally cookie variables (overriding the other two).
$_SERVER
These are variables set by your web server. Traditionally things like DOCUMENT_ROOT, REMOTE_ADDR, REMOTE_PORT, SERVER_NAME, SERVER_PORT, and many others. To get a full list, have a look at your phpinfo( ) output, or run a script like the following to have a look:
<?php
  foreach($_SERVER as $key=>$val) {
    echo '$_SERVER['.$key."] = $val<br>\n";
  }
?>
$_ENV
Any environment variables that were set when you started your web server are available in this array.
$_FILES
For RFC 1867-style file uploads the information for each uploaded file is available in this array. For example, for a file upload form containing:
<input name="userfile" type="file">
The $_FILES array will look something like this:
$_FILES['userfile']['name'] => photo.png
$_FILES['userfile']['type'] => image/png
$_FILES['userfile']['tmp_name'] => /tmp/phpo3kdGt
$_FILES['userfile']['error'] => 0
$_FILES['userfile']['size'] => 158918
Note that the 'error' field is new for PHP 4.2.0 and the values are: 0 no error, file was uploaded); 1 (the uploaded file exceeds the upload_max_filesize directive in php.ini; 2 the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form; 3 the actual number of bytes uploaded was less than the specified upload file size; and 4.

However, having seen some of the possible values of HTTP_USER_AGENT in the last chapter, you can imagine that there are hundreds of slightly different values. So it's time to learn some basic pattern matching.
You'll use the preg_match() function to perform this task. This function needs two arguments: what you're looking for, and where you're looking:

preg_match("/[what you're looking for]/", "[where you're
looking]");
 
This function will return a value of true or false, which you can use in an ifelse block to do whatever you want. The goal of the first script is to determine if a Web browser is Microsoft Internet Explorer, Netscape, or something else. This can be a little tricky, but not because of PHP.
Within the value of HTTP_USER_AGENT, Netscape always uses the string Mozilla to identify itself. Unfortunately, the value of HTTP_USER_AGENT for Microsoft Internet Explorer also uses Mozilla to show that it's compatible. Luckily, it also uses the string MSIE, so you can search for that. If the value of HTTP_USER_AGENT doesn't contain either Mozilla or MSIE, chances are very good that it's not one of those Web browsers.

php tutorial-for beginners

PHP Functions | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,N...

PHP Sessions | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,Ne...

Cookies Versus Sessions? | PHP Interview Questions,PHP tutorial,seo-tips,seo...


PHP Web-Related Variables | PHP Interview Questions,PHP tutorial,seo-tips,se...


MySQL Data on the Web | PHP Interview Questions,PHP tutorial,seo-tips,seo Tu...


php and pdf | php Interview Questions,php tutorial,seo-tips,seo tutorial,Net...

Top Directories submission | PHP Interview Questions,PHP tutorial,seo-tips,...

$_ENV and $_SERVER ? | PHP Interview Questions,PHP tutorial,seo-tips,seo Tut...


What is the use of PEAR in php? | php Interview Questions,php tutorial,seo-t...


SELECTING DATA IN PHP | PHP Interview Questions,PHP tutorial,seo-tips,seo Tu...


THE DIFFERENT TYPES OF ERRORS IN PHP? | PHP Interview Questions,PHP tutorial...


What is the maximum size of a file that can be uploaded using PHP and how ca...


MySQL Database Using PHP | PHP Interview Questions,PHP tutorial,seo-tips,seo...


php file_get_contents | php Interview Questions,php tutorial,seo-tips,seo Tu...


How to prevent hijacking in PHP? | PHP Interview Questions,PHP tutorial,seo...


Php Mysql Image upload | Php Interview Questions,Php tutorial,seo-tips,seo T...


What is LAMP? | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,...


Substrings PHP | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,...

 
Substrings PHP | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,...


PHP MySQL Functions | PHP Interview Questions,PHP tutorial,seo-tips,seo Tuto...


PHP Zip File Functions | PHP Interview Questions,PHP tutorial,seo-tips,seo T...


What are the different tables present in mysql? | PHP Interview Questions,PH...


magic methods? | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,...


$_GET , $_POST,$_COOKIE?? | PHP Interview Questions,PHP tutorial,seo-tips,se...


How get the value of current session id? | PHP Interview Questions,PHP tut...


How register the variables into a session? | PHP Interview Questions,PHP tu...


What is CURL? | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,N...


Free Hosting | PHP Interview Questions,PHP tutorial,seo-tips,seo tutorial,N...

 
 MySQL|PHP Interview Questions,PHP tutorial,seo-tips,seo Tutorial,Networking,...