Sie sind auf Seite 1von 12

A SEMINAR

ON

SUBMMITED TO:- SUBMMITED BY:-


MRS.Semeresh maithi Vaibhav Aggarwal (953)
MCA deptt. Prabhu Jyoti (937)
Pradeep (931)
Baljeet (903)
Geetu(913)

MCA 4th SEM..

***************************************************************************

Paradigm :- imperative, object-oriented,


Procedural, reflective

Appeared in :- 1995; 16 years ago (1995)


Designed by :- Rasmus Lerdorf
Developer :- The PHP Group
Stable release :- (January 6, 2011; 41 days
ago (2011-01-06))
Typing discipline :- Dynamic, weak
Influenced by :- C, Perl, Java, C++,
Implementation language :- C
OS :- Cross-platform
License :- PHP License
Usual file extensions :- .php, .phtml .php5 .phps
Website :- php.net
***************************************************************************

Contents
• 1 History
○ 1.1 Licensing
○ 1.2 Release history
• 2 Usage
• 3 Security
• 4 Syntax
○ 4.1 Data types
○ 4.2 Functions
 4.2.1 PHP 5.2 and earlier
 4.2.2 PHP 5.3 and newer
○ 4.3 Objects
 4.3.1 Visibility of properties and methods
• 5 Speed optimization
• 6 Compilers
• 7 Resources
• 8 See also
• 9 Notes
• 10 External links

1. PHP
PHP stands for P HP: H ypertext P reprocessor
 PHP is a server-side scripting language, like ASP
 PHP scripts are executed on the server
 It is free to download and use
 It is an open source software

 It supports many databases


 MySQL,
 Informix,
 Oracle,
 Sybase,
 Solid,
 PostgreSQL and Generic ODBC, etc.

2. ADVANTAGES
 Open Source, readily available and dual-licensed
 Very Easy to understand Syntax
 Interfaces very easily with Apache/MySQL
 Pretty easy to access other web-based tools through PHP (i.e. google maps,
etc.)
 It's available with documentation in many languages.

3. Disadvantages
 PHP tends to execute more slowly than assembly, C,
and other compiled languages.
 PHP is loosely typed.
 Web programming is open to security flaws due to
unimplemented or unknown vulnerabilities, takes a bit
more caution.

4. How PHP Works? When a user navigates her browser to a page that ends
with a .php extension, the request is sent to a web server, which directs the
request to the PHP interpreter. The PHP interpreter processes the page,
communicating with file systems, databases, and email servers as necessary,
and then delivers a web page to the web server to return to the browser.

5. PHP FILES
○ PHP files can contain text, HTML tags and scripts.
○ PHP files are returned to the browser as plain HTML.
○ PHP files have a file extension of ".php",
".php3", or ".phtml"
○ PHP code is executed on the server, and the plain HTML result is
sent to the browser.
○ A PHP file contains HTML tags and some PHP scripting code.

6. Basic PHP Syntax


 A PHP scripting block always starts with
○ <?php and ends with ?>.
 PHP scripting block can be placed anywhere in the document.
 On servers with shorthand support enabled us to start a scripting block with
○ <? and end with ?>
○ For maximum compatibility, it is recommended that to use the
standard form ( <?php ) rather than the shorthand form.

7. Basic Rules:-
 Each code line in PHP must end with a semicolon .
 The semicolon is a separator and is used to distinguish one set of instructions
from another.
 There are two basic statements to output text with PHP:
 In the eg we have used the echo statement to output the text &quot;Hello World&quot;.
 Note: The file must have a .php extension. If the file has a .html extension , the PHP
code will not be executed.

2. Comments in PHP:
In PHP, we use // to make a single-line comment or /* and */ to make a large
comment block. <html><body> <?php -> Single-line Comment -> Large Comment ?
> </body></html> //This is a comment /* This is a comment block */

3. VARIABLES IN PHP
* Variables are used for storing information values, like text strings, numbers
or arrays.
* When a variable is declared, it can be used over and over again in
your script. * All variables in PHP start with a $ sign symbol.

4. The Settings in which upload directory, register global variables, display errors, log
errors, max uploading size setting, maximum time to execute a script and other
configurations is written in this file. When PHP Server starts up it looks for PHP.ini file
first to load various values for settings.

Php - Presentation Transcript


1. 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. As a general-purpose programming language, PHP code is processed by an
interpreter application in command-line mode performing desired operating system
operations and producing program output on its standard output channel. It may also
function as a graphical application. PHP is available as a processor for most modern
web servers and as standalone interpreter on most operating systems and computing
platforms. PHP was originally created by Rasmus Lerdorf in 1995 and has been in
continuous development ever since. The main implementation of PHP is now
produced by The PHP Group and serves as the de facto standard for PHP as there is
no formal specification. PHP is free software released under the PHP License.
2. 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. PHP can be deployed on most web servers, many operating systems and
platforms, and can be used with many relational database management systems. It is
available free of charge, and the PHP Group provides the complete source code for
users to build, customize and extend for their own use. PHP primarily acts as a filter,
taking input from a file or stream containing text and/or PHP instructions and outputs
another stream of data; most commonly the output will be HTML. Since PHP 4, the
PHP parser compiles input to produce bytecode for processing by the Zend Engine,
giving improved performance over its interpreter predecessor. Originally designed to
create dynamic web pages, PHP now focuses mainly on server-side scripting, and it is
similar to other server-side scripting languages that provide dynamic content from a
web server to a client, such as Microsoft's Active Server Pages, Sun Microsystems'
JavaServer Pages, and mod perl. PHP has also attracted the development of many
frameworks that provide building blocks and a design structure to promote rapid
application development (RAD). Some of these include CakePHP, Symfony,
CodeIgniter, and Zend Framework, offering features similar to other web application
frameworks.
3. How To Install PHP On Linux
This tutorial explains the installation of PHP 5, bundled with Apache and MySQL
server on a Linux machine. The tutorial was written primarily for SuSE 9.2, 9.3, 10.0
& 10.1, but most of the steps ought to be valid for all Linux-like operating systems.
We will set up PHP as a shared module, being loaded into Apache2 dynamically
during the server startup. These instructions are known to work for PHP versions:
5.0.4 through 5.2.1.
Prerequisites
At this point Apache web server must be installed. If you want MySQL support in
PHP, MySQL server also must have been installed prior to the next steps.
Download Source
Get the source from http://www.php.net/downloads.php . At the time of writing this
tutorial the best available version was 5.2.1 ( php-5.2.1.tar.gz ).
4. Unpack, Configure, Compile
Go to the directory whith the downloaded file and enter: # tar -xzf php-5.2.1.tar.gz #
cd php-5.2.1 # ./configure --prefix=/usr/local/php --with-
apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql The configuration
options ought to be self-explaining; --prefix specifies the location where PHP is to be
installed, --with-apxs2 with correct path pointing to bin/apxs in the Apache
installation directory is mandatory for the installator to work. Since PHP 5, you need
to explicitly bundle PHP with MySQL by --with-mysql directive (make sure you
specified path to where MySQL is installed on your system). There are many other
options which turn on additional features. For all available configuration options and
their default values type ./configure --help.
5. TIP :
If you are performing an upgrade, you may want to copy config.nice from the old
PHP installation directory (if available) to where you unpacked the new PHP tarball
file. Run ./config.nice instead of ./configure. This way all the previous configure
options will be applied to the new installation effortlessly. Once you
entered ./configure with all the options you need, compile and install the software: #
make # make install
6. Edit Httpd.conf
All necessary changes to httpd.conf (Apache configuration file) should have already
been made automatically during the installation, so usually you need not do anything.
Nevertheless, check that following lines were added to the httpd.conf file:
LoadModule php5_module modules/libphp5.so AddType application/x-httpd-
php .php If not, add them manually.
Create Php.ini File
Importanly, you have to create a php.ini configuration file. Choose one of the pre-
made files (preferably php.ini-recommended) residing inside the php-5.2.1/ directory
(it's the folder to which the downloaded archive was extracted). Copy the file to the
lib/ directory in the PHP installation directory. # cp php-5.2.1/php.ini-
recommended /usr/local/php/lib/php.ini If you need to, edit the php.ini file: #
vi /usr/local/php/lib/php.ini However, the default settings should work for everyone in
most cases.
7. Restart Apache Server
After everything is set up, restart Apache: # /usr/local/bin/apachectl restart Further
Reading
PHP Manual
Do you have an idea how to make these instructions better? Did you run into any
problems or have any tips? You are welcome to share your experience in the comment
s.
8. PHP CONFIGURATION
PHP's initialization file, generally called php.ini, is responsible for ; configuring
many of the aspects of PHP's behavior. PHP attempts to find and load this
configuration from a number of locations. The following is a summary of its search
order: 1. SAPI module specific location. 2. The PHPRC environment variable. (As of
PHP 5.2.0) 3. A number of predefined registry keys on Windows (As of PHP 5.2.0) 4.
Current working directory (except CLI) 5. The web server's directory (for SAPI
modules), or directory of PHP (otherwise in Windows) 6. The directory from the
--with-config-file-path compile time option, or the Windows directory (C:windows or
C:winnt) See the PHP docs for more specific information.
http://php.net/configuration.file The syntax of the file is extremely simple.
Whitespace and Lines beginning with a semicolon are silently ignored (as you
probably guessed). Section headers (e.g. [Foo]) are also silently ignored, even though
they might mean something in the future.
9. Directives following the section heading [PATH=/www/mysite] only apply to PHP
files in the /www/mysite directory. Directives following the section heading
[HOST=www.example.com] only apply to PHP files served from www.example.com.
Directives set in these special sections cannot be overridden by user-defined INI files
or at runtime. Currently, [PATH=] and [HOST=] sections only work under
CGI/FastCGI. http://php.net/ini.sections 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. The value can be a string, a number, a
PHP constant (e.g. E_ALL or M_PI), one of the INI constants (On, Off, True, False,
Yes, No and None) or an expression (e.g. E_ALL & ~E_NOTICE), a quoted string
(&quot;bar&quot;), or a reference to a previously set variable or directive (e.g. $
{foo})
10. About this file
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 in ; development
environments. ;
php.ini-production contains settings which hold security, performance and ; best
practices at its core. But please be aware, these settings may break ; compatibility
with older or less security conscience applications. We ; recommending using the
production ini in production and testing environments. ;
php.ini-development is very similar to its production variant, except it's ; much more
verbose when it comes to errors. We recommending using the ; development version
only in development environments as errors shown to ; application users can
inadvertently leak otherwise secure information.
11. Quick Reference
The following are all the settings which are different in either the production ; or
development versions of the INIs with respect to PHP's default behavior. ; Please see
the actual settings later in the document for more details as to why ; we recommend
these changes in PHP's behavior. ;
allow_call_time_pass_reference ;
Default Value: On ;
Development Value: Off ;
Production Value: Off ;
display_errors ;
Default Value: On ;
Development Value: On ;
Production Value: Off ;
display_startup_errors ;
Default Value: Off ;
Development Value: On ;
Production Value: Off ;
12. php.ini Options
Name for user-defined php.ini (.htaccess) files. Default is
&quot;.user.ini&quot; ;user_ini.
filename = &quot;.user.ini&quot; ; 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
Language Options
This directive determines whether or not PHP will recognize code between ; <? and ?
> tags as PHP source which should be processed as such. It's been ; recommended for
several years that you not use the short tag &quot;short cut&quot; and ; instead to use
the full <?php and ?> tag combination. With the wide spread use ; of XML and use of
these tags by other languages, the server can become easily ; confused and end up
parsing the wrong code in the wrong context. But because ; this short cut has been a
feature for such a long time, it's currently still ; supported for backwards
compatibility, but we recommend you don't use them.

13. PHP VARIABLES


Variable Types
Variables play an important role in PHP, as they are places for holding values. In
PHP, there is no need to declare variables. Variable can hold eight different data
types: bloolean, integer, float, string, array, object, resource, or NULL.
PHP is a weakly typed language. This means that variable type varies depending on
what is stored in the variable at the time. For example, if we have a variable $a, when
$a = 0, $a is an integer type variable. If later we set $a = &quot;New&quot;, then $a
becomes a string type variable.
Variable Name
A variable name always starts with a $, followed by a letter or an underscore. The
rest of the variable name can be a letter, a number or an underscore. For example,
$dog is a valid variable name, while @dog is not (@dog does not start with a $).
Variables in PHP are case-sensitive.
For example, $Employee and $employee are two different variables.
14. PHP OPERATORS
Assignment Operators The basic assignment operator in PHP is &quot;=&quot;. This
means that the operand to the left of &quot;=&quot; gets set to the value to the right
of &quot;=&quot;.
Arithmetic Operators
Operator Example Result
+ 4+2 6
- 4–2 2
* 4*2 8
/ 4/2 2
% 4%2 0
++ x = 4; x++; x=5
-- x = 4; x--; x=3
Combined Operators
You can combine an arithmetic operator with the assignment operator to form a
combined operator. Combined operators are shown below:
Operator Example Meaning
+= y += x y=y+x
-= y -= x y=y–x
*= y *= x y=y*x
/= y /= x y=y/x
%= y %= x y=y%x
15. Comparison Operators
Operator Meaning
== is equal to
!= is not equal to
> is greater than
>= is greater than or equal to
< is less than
<= is less than or equal to
Logical Operators
Operator Meaning
|| or
&& and
and and
or or
xor xor
! not
16. PHP IF ELSE
IF..ELSE is used in PHP to provide conditional judgements. The basic syntax is as
follows:
IF (conditional statement)
{ [code if condition is true] }
ELSE
{ [code if condition is false] }
Let's see an example. Assuming we have the following piece of code:
$sample = 10;
IF ($sample > 5)
{ print &quot;Number is greater than 5&quot;; }
ELSE
{ print &quot;Number is less than 5&quot;; }
The output of the above code is:
Number is greater than 5
17. PHP FUNCTIONS
Similar to other programming languages, PHP provides a way for programmers to
define functions, which can then be called elsewhere in the program. The syntax for a
function is:
function &quot;function_name&quot; (arg1, arg2...)
{
[code to execute]
return [final_result];
}
where [final_result] is typically the variable holding the final value to be returned
from the function.
Let's take a look at an example:
function double_this_number($input_number)
{ return $input_number*2; }
Elsewhere in the PHP code,
we have
$x = 10;
$y = double_this_number($x);
print $y;
The output will be 20
18. PHP ARRAYS
An array is a way of holding multiple closely-related values, such as the test scores of
all students in a class. An array is made up of a key and a value, and the key points to
the value.
There are two types of arrays:
Indexed array
and Associative array.
Their difference is in the way the key is specified.Let's look at both of them:
Indexed Array
In an indexed array, the keys are numeric and starts with 0, and the values can be any
data type.
The following shows two ways of assigning values to an indexed array:
$friends = array(“Sophie”,”Stella”,”Alice”);
This is equivalent to the following
$friends[0] = Sophie
$friends[1] = Stella
$friends[2] =Alice;
19. PHP FORMS
One of the main features in PHP is the ability to take user input and generate
subsequent pages based on the input. In this page, we will introduce the mechanism
by which data is passed in PHP.
Let's consider the following two files:
query.php
<form action=result.php type=post> <input type=text name=employee> <input
type=submit value=Submit> </form>
result.php
<?php $employee_name = $_POST[&quot;employee&quot;]; print
$employee_name; ?>
20. PHP COOKIES
Create cookies Cookies are set using the setcookie() function. The syntax is as
follows: Setcookie (name, value, expire, path, domain, secure)
name = name of the cookie.
value = value of the cookie.
expire = time when this cookie will expire.
Unix time is used here.
path = the path on the server on which the cookie is available.
domain = the domain that the cookie is available.
secure = TRUE means the cookie should be trasmitted over a secure connection
(https), FALSE otherwise. FALSE is the default.
All arguments except name are optional. Unix time is the number of seconds that have
elapsed since January 1, 1970. You must make sure that the setcookie() function is
called before any HTML output is printed. Let's take a look at a couple of examples:
<?php setcookie('cookie1','lisa'); ?>
21. PHP MYSQL
The PHP code needed is as follows (assuming the MySQL Server sits in localhost
and has a userid = 'cat' and a password of 'dog', the database name is 'myinfo') :
$link = @mysql_pconnect(“localhost”;”cat”;”dog”) or exit();
22. PHP SYNTAX
DO ... WHILE
DO
{ [code to execute] }
WHILE (conditional statement)
ELSEIF
IF (conditional statement 1)
{ [code if condition statement 1 is true] }
ELSEIF (conditional statement 2)
{ [code if condition statement 2 is true] }
ELSE
{ [code if neither statement is true] }
FOR Loop
FOR (expression 1, expression 2, expression 3)
{ [code to execute] }
23. FOREACH Loop
FOREACH ($array_variable as $value)
{ [code to execute] }
or
FOREACH ($array_variable as $key => $value)
{ [code to execute] }

IF ELSE
IF (conditional statement)
{ [code if condition is true] }
ELSE
{ [code if condition is false] }
24. Include INCLUDE (&quot;external_file_name&quot;);
SWITCH ($variable)
{ CASE 'value 1':
[code to execute when $variable = 'value 1']
break;
CASE 'value 2':
[code to execute when $variable = 'value 2']
break;
CASE 'value 3'
: ...
DEFAULT:
[code to execute when none of the CASE values matches $variable']
}

WHILE Loop
WHILE (expression)
{ [code to execute] }
25. THANK YOU

Das könnte Ihnen auch gefallen