0% found this document useful (0 votes)
4 views

PHP.

The document provides an overview of PHP, a server-side scripting language used for creating dynamic web pages, detailing its history, characteristics, advantages, and disadvantages. It explains PHP's architecture in relation to web servers, environment variables, and data types, along with examples of variable declaration and usage. Additionally, it covers PHP constants, data types, and object-oriented programming concepts.

Uploaded by

incharagangatkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PHP.

The document provides an overview of PHP, a server-side scripting language used for creating dynamic web pages, detailing its history, characteristics, advantages, and disadvantages. It explains PHP's architecture in relation to web servers, environment variables, and data types, along with examples of variable declaration and usage. Additionally, it covers PHP constants, data types, and object-oriented programming concepts.

Uploaded by

incharagangatkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

INTERNET TECNOLOGY

Presented By:
PREETHI V M
Assistant Professor
Department of Master of Computer Science
INTRODUCTION TO
PHP
PHP IS A SERVER SIDE SCRIPTING LANGUAGE WHICH IS USED TO CREATE
DYNAMIC WEB PAGES.
PHP

• PHP started out as a small open source project that evolved as more and more people found
out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.
• PHP is an acronym for "PHP: Hypertext Preprocessor"
• PHP is a widely-used, open source scripting language
• PHP scripts are executed on the server
• PHP is free to download and use
• PHP is forgiving: PHP language tries to be as forgiving as possible.
• PHP Syntax is C-Like.
WHY PHP

• PHP runs on various platforms.


• PHP Supports many database, including MySQL, Oracle, Sybase.
• PHP is Free.
• PHP is easy to learn and runs efficiently on the server side.
• PHP is Compatible.
CHARACTERISTICS OF PHP

• Simplicity
• Efficiency
• Flexibility
• Familiarity
• Security
• Open Source
• Reliability
ADVANTAGES OF PHP

• Speed
• Easy to use
• Stable
• Platform Independent
• Open Source
• Built-in database connection modules
• Powerful library support
DISADVANTAGES OF PHP

• Security
• Weak Type
• Not appropriate for big application
• Not smart to create desktop Applications.
PHP AND WEB SERVER ARCHITECTURE

• This system consists of two objects : a web browser and a web server.
• A communication link is required between them. A web browser makes a request of the
server. The server sends back a response.
• This Architecture suits a server delivering static pages well and that delivers a database
backed website.

The client/server relationship between a Web browser and Web server requires communication
WEB SERVER ARCHITECTURE

• A users Web browser issues an HTTP request for a particular web page.
• The Web Server receives the request for results. PHP retrieves the file and passes it to
the PHP engine for processing.
• The PHP engine starts parsing the script. PHP opens a connection to the MySQL server
sends on the appropriate query.
• The MySQL server receives the database query and processes it and sends the results
list of books back to the PHP engine.
PHP CAPABILITIES

• Cross Platform
• Extensions
• Easy access to the tools
• Embedding
• Anytime Support
• Flexibility
• Open Source
PHP AND HTTP ENVIRONMENT VARIABLE

• A PHP environment variable permits us scripts to obtain certain types of data


dynamically from the server.
• When a web browser makes a request of a web server, it sends along with the request a
list of extra variables called environment variables.
• The phpinfo() function displays a wealth of information about our Web Server software
and the version of PHP we are running, in addition to the basic HTTP environment.
CONTD…

1. Open a new file in our Text Editor.


2. Type the following line of PHP code: <? Phpinfo(); ?>
3. Save the file with the name phpinfo.php and place the file in the
document root of your Web Server.
CONTD..

• $_ENV is used to return the environment variables from the web server.
• Example: <? Php
echo $_ENV[‘username’]
?>
• There are two methods of $_ENV: putenv() and getenv()
• PHP global environment variables include: $_SERVER, $_GET ,$_FILES, $_POST,
$_COOKIE etc.
LIST OF PHP AND HTTP ENVIRONMENT VARIABLES

• PATH_INFO
• PATH_TRANSLATED
• SCRIPT_NAME
• SCRIPT_FILENAME and REQUEST_FILENAME
• URL
• SCRIPT_URL and REQUEST_URL
• REQUEST_METHOD
• QUERY_STRING
• CONTENT_TYPE
• CONTENT_LENGTH
• AUTH_TYPE
CONTD..

• AUTH_USER and REMOTE_USER


• ALL_HTTP
• ALL_RAW
• SERVER_SOFTWARE
• SERVER_NAME
• SERVER_ADDR
• SERVER_PORT
• SERVER_PROTOCOL
• GATEWAY_INTERFACE
• REMOTE_ADDR
• REMOTE_PORT
• IS_SUBREQ
PHP VARIABLES

• A variable is a temporary container that can hold a value.


• Variables in PHP are identifiers prefixed with a dollar sign $
Rules for PHP variables:
1. A variable starts with the $ sign, followed by the name of the variable
2. A variable name must start with a letter or the underscore character
3. A variable name cannot start with a number
4. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
5. Variable names are case-sensitive ($age and $AGE are two different variables)
EXAMPLE OF PHP VARIABLES

<?php

$txt = “Php variables";

echo "I love $txt!"; ?>

Output: I love Php variables!


DEFINING VARIABLES:

• A variable stores a value of any type. For example: string number, array, object, or
resource. A variable has a name and value.
• Syntax to define a variable: $variable_name=value;
• For example : $name
$Net_Sa006C
• In PHP variable declaration means setting a value to a variable.
CREATING (DECLARING) PHP VARIABLES

• <?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
Output:
Hello world!
5
10.5
VARIABLE DECLARATION:

• A variable declaration is a named memory location that contains data that may be
manipulated throughout the execution of the script.
• Variables are declared when first used in PHP. Variables in PHP are identifiers prefixed
with a dollar sign:$.
• Syntax: $variable;
PHP CONSTANTS

• A constant is an identifier (name) for a simple value. The value cannot be changed during the script.

• A valid constant name starts with a letter or underscore (no $ sign before the constant name)

• A constants is case-sensitive by default.

• Value of constants are set using the define() function

Create a PHP Constant


• To create a constant, use the define() function.
Syntax:- define(name, value, case-insensitive)
Parameters:
• name: Specifies the name of the constant
• value: Specifies the value of the constant
• case-insensitive: Specifies whether the constant name should be case-
insensitive. Default is false

Example
<!DOCTYPE html>
<html>
<body>
<?php
// case-sensitive constant name
define("GREETING", "Welcome to jss collage.com!");
echo GREETING;
?>
</body>
</html>
PHP DATA TYPES(PRIMITIVES)

• Variables can store data of different types, and different data types can do different things.
• PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• Object
• NULL
• Resource
PHP STRING

• A string is a sequence of characters, like "Hello world!".


• A string can be any text inside quotes. You can use single or double quotes
• example:
<?php
$x = "Hello world!";
$y = 'Hello world!';

echo $x;
echo "<br>";
echo $y;
?>
Output:
Hello world!
Hello world!
PHP INTEGER

• An integer data type is a non-decimal number between -2,147,483,648 and


2,147,483,647.
• Rules for integers:
• An integer must have at least one digit
• An integer must not have a decimal point
• An integer can be either positive or negative
• Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or
binary (base 2) notation
EXAMPLE FOR PHP INTEGER

• In the following example $x is an integer. The PHP var_dump() function returns the data type
and value:

<?php
$x = 5985;
var_dump($x); ?>

Output: int(5985)
PHP FLOAT

• A float (floating point number) is a number with a decimal point or a number in


exponential form.
• In the following example $x is a float. The PHP var_dump() function returns the data type
and value:

<?php $x = 10.365;
var_dump($x); ?>
OUTPUT: Float(10.365)
PHP BOOLEAN

• A Boolean represents two possible states: TRUE or FALSE.


• $x = true;
$y = false;
• Booleans are often used in conditional testing.
PHP ARRAY

• An array stores multiple values in one single variable.


• In the following example $cars is an array. The PHP var_dump() function returns the data type and
value:

• Example:

• <?php $cars = array("Volvo","BMW","Toyota");


• var_dump($cars); ?>
PHP OBJECT

• Classes and objects are the two main aspects of object-oriented programming.
• A class is a template for objects, and an object is an instance of a class.
• When the individual objects are created, they inherit all the properties and behaviors from
the class, but each object will have different values for the properties.
EXAMPLE OF PHP OBJECT

class Person

Public $name = ‘ ‘;

Function name($newname)

$this-> name=$newname; } }

$p = new person();

$p->name(“preethi”);

Echo “hello $p->name”;


PHP NULL VALUE

• Null is a special data type which can have only one value: NULL.
• A variable of data type NULL is a variable that has no value assigned to it.
• Example:
<?php $x = "Hello world!";
$x = null;
var_dump($x); ?>
OUTPUT: null
THANK YOU

You might also like