PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.Even a non technical person can cretae sites using its CMS.WordPress,osCommerce are the famous CMS of php.It is also an object oriented programming language like java,C-sharp etc.It is very eazy for learning
The PHP configuration file, php.ini, is the final and most immediate way to affect PHP's functionality. The php.ini file is read each time PHP is initialized.in other words, whenever httpd is restarted for the module version or with each script execution for the CGI version. If your change isn.t showing up, remember to stop and restart httpd. If it still isn.t showing up, use phpinfo() to check the path to php.ini.
PHP syntax resembles Perl and C
PHP has a total of eight data types which we use to construct our variables −
It is used to print a data in the webpage, Example: <?php echo 'Car insurance'; ?> , The following code print the text in the webpage.
echo() and print() function both are used to show the output on the visitors screen but in echo we can take one or more parameters.
print() has a return value of true or false whereas echo has a void return type.
echo() is slightly faster than print.
The PHP default variable $_PHP_SELF is used for the PHP script name and when you click "submit" button then same PHP script will be called.
PHP provided setcookie() function to set a cookie. This function requires upto six arguments and should be called before <html> tag. For each cookie this function has to be called separately.
setcookie(name, value, expire, path, domain, security);
You can use isset() function to check if a cookie is set or not.
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.
We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method
PHP and Javascript cannot directly interacts since PHP is a server side language and Javascript is a client side language. However we can exchange variables since PHP is able to generate Javascript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.
Setcookie("sample", "ram", time()+3600);
$message is a variable with a fixed name. $$message is a variable whose name is stored in $message.
If $message contains "var", $$message is the same as $var.
This function is used to determine if a variable is set and is not NULL
The action attribute determines where to send the form-data in the form submission.
A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests. Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.
The header() function sends a raw HTTP header to a client.We can use header() function for redirection of pages. It is important to notice that header() must be called before any actual output is seen.
Notices, Warnings and Fatal errors are the types of errors in PHP
Notices: Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior.
Warnings: Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user.
Fatal errors: Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.
By default the PHP script takes 30secs to execute. This time is set in the php.ini file. This time can be increased by modifying the max_execution_time in seconds. The time must be changed keeping the environment of the server. This is because modifying the execution time will affect all the sites hosted by the server.
Constants in PHP are defined using define() directive, like define("MYCONSTANT", 100);
Javascript is a client side scripting language, so javascript can make popups and other things happens on someone’s PC. While PHP is server side scripting language so it does every stuff with the server.
default session time in PHP is 1440 seconds or 24 minutes
Default session save path id temporary folder /tmp
.htaccess is a configuration file running on Apache server.These .htaccess file used to change the functionality and features of apache web server .
eg. .htaccess file used for url rewrite .
.htaccess file used to make the site password protected.
.htaccess file can restrict some ip addresses ,so that on restricted ip adresses site will not open.
PEAR is known as PHP Extension and Application Repository. It provides structured library to the PHP users and also gives provision for package maintenance.
The unlink() function is dedicated for file system handling. It simply deletes the file given as entry.
The unset() function is dedicated for variable management. It will make a variable undefined.
The substr () function is used to return the part of a string located between a predefined starting offset and length position.
PHP supports many databases like dBase, Microsft SQL Server, Oracle, etc. But, it also supports databases like filePro, FrontBase and InterBase with ODBC connectivity. ODBC stands for Open Database connectivity, which is a standard that allows user to communicate with other databases like Access and IBM DB2.
When a function is called by itself then that function is called recursive function.
It is used for sort an array by key in reverse order.
Web services converts our applicaton into a web-application ,which can publish its functions and messages to the internet users.The main web services platform is XML and HTTP.Web services can be published ,found and used through web.
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.
exit() function is used to stop the execution of a page
We can change the time zones by using date_default_timezone_set() function.
e.g :
<?php
date_default_timezone_set('America/Los_Angeles');
?>
The use of the function session_start() lets us activating a session.
A persistent cookie is permanently stored in a cookie file on the browser’s computer. By default, cookies are temporary and are erased if we close the browser.
Sessions automatically ends when the PHP script finishs executing, but can be manually ended using the session_write_close().
The session_unregister() function unregister a global variable from the current session and the session_unset() function free all session variables.
Magic methods are very easy to identify, that every magical method name is started with double underscore( __)sign. We can not declare any user-defined functions with __ sign.
$GLOBALS is associative array including references to all variables which are currently defined in the global scope of the script.
Public : The items which are declared public can be access from everywhere ie access from inside the class ,access in inherited class and access from outside the class.
Protected : The items which are declared protected can be access inside the class that defines the item and can acess in its child classes (ie access in its inherited class) .
Private : The items which are declared private can only be access inside its class that defines the item.
$_SERVER is an array including information created by the web server such as paths, headers, and script locations.
$_FILES is an associative array composed of items sent to the current script via the HTTP POST method.
$_ENV is an associative array of variables sent to the current PHP script via the environment method.
$_COOKIE is an associative array of variables sent to the current PHP script using the HTTP Cookies.
The function get_included_files () function is used to get the names of all required and included files in a page . It returns an array with the names of included and required files in a page
We have two functions to get the number of elements in an array ie count() and sizeof().
Synatx : count ($array_name) and sizeof($array_name)
Split function splits string into array by regular expression. Explode splits a string into array by string.
strlen() function used to find the length of a string
Associative arrays are arrays that use string keys is called associative arrays.
Unlink() deletes the given file from the file system.
session_id() function returns the session id for the current session.
strpos() is used to find the position of the first occurrence of a substring in a string
!= means inequality (TRUE if $a is not equal to $b) and !== means non-identity (TRUE if $a is not identical to $b).
The function parse_ini_file() enables us to load in the ini file specified in filename, and returns the settings in it in an associative array.
The function eregi_replace() is identical to the function ereg_replace() except that it ignores case distinction when matching alphabetic characters.
Yes, it is possible by setting the cookie with a past expiration time.
The default session time in php is until closing of browser
Yes, it’s possible to integrate (Distributed) Component Object Model components ((D)COM) in PHP scripts which is provided as a framework.
No, a parent constructor have to be called explicitly as follows:
parent::constructor($value)
__sleep returns the array of all the variables that need to be saved, while __wakeup retrieves them.
Full form of MIME is "Multi-purpose Internet Mail Extensions".
It is extension of e-mail protocol helps to exchanges the different kids of data files over the internet.
Data files may be audio, video, images, application programs and ASCII etc.
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.
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
SQL or Structured Query Language is a programming language designed for managing data held in a Relational Database Management System. Mysql is a open source, relational database management System.
SQL injection is a malicious code injection technique.It exploiting SQL vulnerabilities in Web applications
in_array used to checks if a value exists in an array
We can change the maximum size of files to be uploaded by changing upload_max_filesize in php.ini.
A session is a logical object enabling us to preserve temporary data across multiple PHP pages.
UML stands for Unified Modeling Language.
You can do following things with UML
:: is used to access static methods that do not require object initialization.
$_SERVER[‘HTTP_USER_AGENT’] global variable is used to get the browser properties.
Inserts HTML line breaks (
) before all newlines in a string.
$second = date("s");
SELECT CURDATE(); CURRENT_DATE() = CURDATE() for time use SELECT CURTIME(); CURRENT_TIME() = CURTIME()
Using URL rewriting we can convert dynamic URl to static URL Static URLs are known to be better than Dynamic URLs because of a number of reasons
1. Static URLs typically Rank better in Search Engines.
2. Search Engines are known to index the content of dynamic pages a lot slower compared to static pages.
3. Static URLs are always more friendlier looking to the End Users. along with this we can use URL rewriting in adding variables [cookies] to the URL to handle the sessions.
This is the encoding used to send image or files via form, The data will be split into multiple parts and, one for each files plus one for the text of the form body that may be sent with them.
Once a file is opened using fopen() function it can be read with a function called fread(). This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes.
parent::constructor();
PHP provides many ways to access cookies. Simplest way is to use either $_COOKIE or $HTTP_COOKIE_VARS variables.
Using $_FILES['file']['tmp_name'] − it provides access to the uploaded file in the temporary directory on the web server.
The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern.
There are Five Types Tables in Mysql
Database name: 64 characters
Table name: 64 characters
Column name: 64 characters
Arithmetic operators are operating a value using the operator addition, subtraction, multiplication, division and modulus.
The logical operators are used to checking the condition. If the condition is satisfied they TRUE otherwise return False.
The switch statement in PHP is used to perform one of several different actions based on one of several different conditions. If you want to select one of many blocks of code to be executed, use the switch statement. The switch statement is used to avoid long blocks of if..alseif...else code.
Break ends execution of the current for, foreach, while, do .. while or switch structure. Break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of.
ISAM stands for Indexed Sequential Access Method, a method for indexing data for fast retrieval.
NOW () is used to show current year,month,date, hours,minutes and seconds.
CURRENT_DATE() shows current year,month and date only.
SHOW DATABASES;
SELECT DATEDIFF('2010-10-22', '2010-10-19');
We can use the hyperlinks to submit a form if we don't want to use submit button. We have to use some java script code for that.
<a href="javascript:document.myform.submit();"> Submit me
GET and POST.
The Date() function is used to format a date.
File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once().
Files in PHP can be uploaded using move_uploaded_file(string filename, string destination).
PHP is an interpreted language.
The opendir() function enables you to open a directory for reading.
PHP's configuration file is called php.ini.
The fgets() function reads data up to the buffer size you pass it, the end of the line, or the end of the document, whichever comes first.
The filesize() function returns a file's size in bytes.
The Apache configuration file is called httpd.conf.
PHP function would you use to send an email with the mail() function.
The dba_insert() function adds a record to a database.
Two types of data can be used as array keys: string and integer. When a string is used as a key and the string represent an integer, PHP will convert the string into a integer and use it as the key.
You can merge arrays with the array_merge() function.
There are three different kind of arrays:
Numeric array - An array with a numeric ID key.
Associative array - An array where each ID key is associated with a value.
Multidimensional - An array containing one or more arrays.
The dba_replace() function replace a record in a database.
session_register() is old function that register global variables into the current session.
The mysql_select_db() function attempts to select a database.
file_get_contents() lets reading a file and storing it in a string variable.
5 types of tables presents in mysql database.
Use this for mysql:
SELECT COUNT(*) FROM table_name;
ADDDATE(techpreparation_publication_date, INTERVAL 3 MINUTE).
To be able to display a human-readable result we use print_r().
The result set can be handled using mysql_fetch_array, mysql_fetch_assoc, mysql_fetch_object or mysql_fetch_row.
mysql_affected_rows() return the number of entries affected by an SQL query.
The mysql_fetch_object() function collects the first single matching record where mysql_fetch_array() collects all matching records from the table in an array.
It is possible to use the dedicated function, is_numeric() to check whether it is a number or not.
It is possible to use the dedicated function, ctype_alnum to check whether it is an alphanumeric value or not.
If we want to check whether a variable has a value or not, it is possible to use the empty() function.
The function get_magic_quotes_gpc() tells us whether the magic quotes is switched on or no.
The strip_tags() function enables us to clean a string from the HTML tags.
To be able to pass a variable by reference, we use an ampersand in front of it, as follows $var1 = &$var2
!= means inequality (TRUE if $a is not equal to $b) and !== means non-identity (TRUE if $a is not identical to $b).
Yes, it’s possible to integrate (Distributed) Component Object Model components ((D)COM) in PHP scripts which is provided as a framework.
$a and $b: TRUE if both $a and $b are TRUE.
$a & $b: Bits that are set in both $a and $b are set.
$a === $b TRUE if $a and $b have the same key/value pairs in the same order and of the same types.
The function unlink() is to remove a file, where as unset() is used for destroying a variable that was declared earlier.
unset() empties a variable or contents of file.
Super global arrays are the built in arrays that can be used anywhere. They are also called as auto-global as they can be used inside a function as well. The arrays with the longs names such as $HTTP_SERVER_VARS, must be made global before they can be used in an array. This $HTTP_SERVER_VARS check your php.ini setting for long arrays.
mysql_fetch_row()
mysql_fetch_array()
mysql_fetch_object()
mysql_fetch_assoc()
exit() function is used to stop the execution of a page.
It is used to generate random numbers. If called without the arguments it returns a pseudo-random integer between 0 and getrandmax(). If you want a random number between 6 and 12 (inclusive), for example, use rand(6, 12).This function does not generate cryptographically safe values, and should not be used for cryptographic uses. If you want a cryptographically secure value, consider using openssl_random_pseudo_bytes() instead.
SQL injection is a malicious code injection technique. It exploiting SQL vulnerabilities in Web applications
PHP includes only single inheritance, it means that a class can be extended from only one single class using the keyword ‘extended’.
The functions are getimagesize() for size, imagesx() for width and imagesy() for height.
It is preferable to use crypt() which natively supports several hashing algorithms or the function hash() which supports more variants than crypt() rather than using the common hashing algorithms such as md5, sha1 or sha256 because they are conceived to be fast. hence, hashing passwords with these algorithms can vulnerability.
CONSTRUCTOR : PHP allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
DESTRUCTORS : PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence.
MVC stands for Model, View, and Controller. PHP MVC is an effective way to manage the code into 3 different layers.
Model: Model represents the information in application.
View: View represents the visual representation of information and data that you have entered in the application.
Controller: Controller is actually how and in which way you want to read the information in application.
The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. It is a data-access abstraction layer, so no matter what database we use the function to issue queries and fetch data will be same. Using PDO drivers we can connect to database like DB2, Oracle, PostgreSQL etc.
It is used to escapes special characters in a string for use in an SQL statement
Static Websites : A webpage or website which was developed by using HTML alone.
Dynamic Websites :A webpage or website which was developed by using any dynamic languages like PHP, ASP.NET, JSP etc
ZEND Engine 2 is the name of the scripting engine that powers PHP.
md5() – Calculate the md5 hash of a string
sha1() – Calculate the sha1 hash of a string
hash() – Generate a hash value
crypt() – One-way string hashing
The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can’t print any HTML element before using this header function.
Array is used to store multiple values in single value. In PHP, it orders maps of pairs of keys and values. It stores the collection of data type.
CakePHP
CodeIgniter
Yii 2
Symfony
Zend Framework etc.
Note: Click on the linked heading text to expand or collapse accordion panels.