Top Banner
PHP: Hypertext Preprocessor PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document.
25
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Php

PHP: Hypertext Preprocessor

PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document.

Page 2: Php

Usage:

PHP is a general-purpose scripting language that is especially suited to server-side web development where PHP generally runs on a web server. Any PHP code in a requested file is executed by the PHP runtime, usually to create dynamic web page content. It can also be used for command-line scripting and client-side GUI applications.

Page 3: Php

As of April 2007, over 20 million Internet domains had web services hosted on servers with PHP installed and mod_php was recorded as the most popular Apache HTTP Server module. Significant websites are written in PHP including the user-facing portion of Facebook, Wikipedia (MediaWiki), Yahoo!, MyYearbook,Digg,Joomla, eZ Publish, WordPress, YouTube in its early stages, Drupal, Tagged and Moodle.

Page 4: Php

The National Vulnerability Database stores all vulnerabilities found in computer software. The overall proportion of PHP-related vulnerabilities on the database amounted to: 20% in 2004, 28% in 2005, 43% in 2006, 36% in 2007, 35% in 2008, and 30% in 2009. Most of these PHP-related vulnerabilities can be exploited remotely: they allow crackers to steal or destroy data from data sources linked to the webserver (such as an SQL database), send spam or contribute to DoS attacks using malware, which itself can be installed on the vulnerable servers.

Security:

Page 5: Php

Syntax: PHP only parses code within its delimiters. Anything outside

its delimiters is sent directly to the output and is not processed by PHP (although non-PHP text is still subject to control structures described within PHP code). The most common delimiters are <?php to open and ?> to close PHP sections. <script language="php"> and </script> delimiters are also available, as are the shortened forms <? or <?= (which is used to echo back a string or variable) and ?> as well as ASP-style short forms <% or <%= and %>. While short delimiters are used, they make script files less portable as their purpose can be disabled in the PHP configuration, and so they are discouraged.The purpose of all these delimiters is to separate PHP code from non-PHP code, including HTML

Page 6: Php

<html> <head> <title>PHP Test</title> </head> <body> <?php echo "Hello World"; /* echo("Hello World"); works as well, although echo isn't a function (it's a language construct). In some cases, such as when multiple parameters are passed to echo, parameters cannot be enclosed in parentheses */ ?> </body></html>

Example:

Page 7: Php

INSTALLATION

Page 8: Php

Again the installation of the php editor will need the xampp server[is a free and open source cross-platform web server package, consisting mainly of the

Apache HTTP Server, MySQL database, and interpreters for

scripts written in the PHP and Perl programming languages.]

Step 1: We need to have the xampp for linux inorder the run applications

so(as per step 1) ,download the xampp for linux with any favourable version on to the computer

Page 9: Php

Step 2: After the successful downloading,we need to extract the 'tar' file on to the system,select a path and just extract them using the following

commands

gunzip -d httpd-2_0_NN.tar.gz tar xvf httpd-2_0_NN.tar

*NN -refers to the current xampp version

Page 10: Php

CONFIGURATION

Page 11: Php

PHP comes packaged with two INI files. One that is recommended to be used in production environments and one that is recommended to be used indevelopment environments.

php.ini-production contains settings which hold security, performance andbest practices at its core. But please be aware, these settings may breakcompatibility with older or less security conscience applications. Werecommending using the production ini in production and testing

environments.

php.ini-development is very similar to its production variant, except it'smuch more verbose when it comes to errors. We recommending using thedevelopment version only in development environments as errors shown

to application users can inadvertently leak otherwise secure information.

CONFIGURATION FILE

Page 12: Php

Directives are specified using the following syntax: directive = value

Directive names are *case sensitive* - foo=bar is different from FOO=bar.

Directives are variables used to configure PHP or PHP extensions.There is no name validation. If PHP can't find an expected directive because it is not set or is mistyped, a default value will be used.

DIRECTORIES SPECIFICATION

Page 13: Php

EXPRESSIONS:

Expressions in the INI file are limited to bitwise operators and parentheses:

| bitwise OR ^ bitwise XOR & bitwise AND ~ bitwise NOT ! boolean NOT

Page 14: Php

EMPTY STRINGS:

An empty string can be denoted by simply not writing anything after the equal sign, or by using the None keyword:

ABC = ; sets foo to an empty string ABC = None ; sets foo to an empty string ABC = "None" ; sets foo to the string

'None'

*ABC -SECTION HEADER

Page 15: Php

php.ini OPTIONSName for user-defined php.ini (.htaccess) files.

Default is ".user.ini"user_ini.filename = ".user.ini"

To disable this feature set this option to empty value

user_ini.filename =

TTL for user-defined php.ini files (time-to-live) in seconds. Default is 300 seconds (5 minutes)

user_ini.cache_ttl = 300

Page 16: Php

LANGUAGE OPTIONS

Enable the PHP scripting language engine under Apache.

http://php.net/engineengine = On

Page 17: Php

SAFE MODE:Safe Modehttp://php.net/safe-modesafe_mode = Off

By default, Safe Mode does a UID compare check whenopening files. If you want to relax this to a GID compare,then turn on safe_mode_gid.http://php.net/safe-mode-gidsafe_mode_gid = Off

When safe_mode is on, UID/GID checks are bypassed whenincluding files from this directory and its subdirectories.(directory must also be in include_path or full path mustbe used when including)http://php.net/safe-mode-include-dirsafe_mode_include_dir =

When safe_mode is on, only executables located in the safe_mode_exec_dirwill be allowed to be executed via the exec family of functions.http://php.net/safe-mode-exec-dirsafe_mode_exec_dir

Page 18: Php

Functions and classes This directive allows you to disable certain functions for

security reasons. It receives a comma-delimited list of function names. This

directive is *NOT* affected by whether Safe Mode is turned On or Off. http://php.net/disable-functionsdisable_functions =

This directive allows you to disable certain classes for security reasons.

It receives a comma-delimited list of class names. This directive is

*NOT* affected by whether Safe Mode is turned On or Off. http://php.net/disable-classesdisable_classes =

Page 19: Php

Color highlighting

Colors for Syntax Highlighting mode. Anything that's acceptable in

<span style="color: ???????"> would work. http://php.net/syntax-highlightinghighlight.string = #DD0000highlight.comment = #FF9900highlight.keyword = #007700highlight.bg = #FFFFFFhighlight.default = #0000BBhighlight.html = #000000

Page 20: Php

RESOURCE LIMITS Maximum execution time of each script, in seconds http://php.net/max-execution-time Note: This directive is hardcoded to 0 for the CLI SAPImax_execution_time = 30

Maximum amount of time each script may spend parsing request data. It's a good idea to limit this time on productions servers in order to eliminate unexpectedly long running scripts. Note: This directive is hardcoded to -1 for the CLI SAPI Default Value: -1 (Unlimited) Development Value: 60 (60 seconds) Production Value: 60 (60 seconds) http://php.net/max-input-timemax_input_time = 60

Maximum input variable nesting level http://php.net/max-input-nesting-levelmax_input_nesting_level = 64

Maximum amount of memory a script may consume (128MB) http://php.net/memory-limitmemory_limit = 128M

Page 21: Php

Error handling and logging; This directive informs PHP of which errors, warnings and notices you

would like; it to take action for. The recommended way of setting values for this; directive is through the use of the error level constants and bitwise; operators. The error level constants are below here for convenience as

well as; some common settings and their meanings.; By default, PHP is set to take action on all errors, notices and warnings

EXCEPT; those related to E_NOTICE and E_STRICT, which together cover best

practices and; recommended coding standards in PHP. For performance reasons, this is

the; recommend error reporting setting. Your production server shouldn't be

wasting; resources complaining about best practices and coding standards.

That's what; development servers and development settings are for.

Page 22: Php

Error Level Constants:

E_ALL - All errors and warnings E_ERROR - fatal run-time errorsE_RECOVERABLE_ERROR - almost fatal run-time errorsE_WARNING - run-time warnings (non-

fatal errors)E_PARSE - compile-time parse

errorsE_COMPILE_ERROR - fatal compile-time errorsE_USER_ERROR - user-generated error messageE_USER_WARNING - user-generated warning messageE_USER_NOTICE - user-generated notice messageE_DEPRECATED - warn about code that will not work

in future versions of php

Page 23: Php

Paths and Directories:

UNIX: "/path1:/path2"include_path = ".:/php/includes"

Windows: "\path1;\path2"include_path = ".;c:\php\includes"

PHP's default setting for include_path is "/path/to/php/pear"

Page 24: Php

FILE UPLOADS:

Whether to allow HTTP file uploads.http://php.net/file-uploadsfile_uploads = On

Temporary directory for HTTP uploaded files (will use system default if notspecified).

http://php.net/upload-tmp-dirupload_tmp_dir =

Maximum allowed size for uploaded files.http://php.net/upload-max-filesizeupload_max_filesize = 2M

Page 25: Php

DYNAMIC EXTENSIONS: If you wish to have an extension loaded automatically, use the

following syntax:

extension=modulename.extension

For example, on Windows:

extension=msql.dll

... or under UNIX:

extension=msql.so

... or with a path:extension=/path/to/extension/msql.so