SlideShare une entreprise Scribd logo
1  sur  59
Télécharger pour lire hors ligne
PHP:
Hypertext
Preprocessor
Content
 What is Server?
 Types of servers.
 Basic PHP.
 Syntax of PHP.
 Variables.
 Operators.
 Conditional Statements.
 Loops.
 PHP Function.
 PHP Array & It‟s types.
What is Server ?
 In a technical sense, a server is an instance of a computer
program that accepts and responds to requests made by
another program, known as a client.
 Less formally, any device that runs server software could be
considered a server as well.
 Servers are used to manage network resources.
 For example, a user may setup a server to control access to
a network, send/receive e-mail, manage print jobs, or host
a website.
What is Server ? (cont.)
 Some servers are committed to a specific task, often referred to as
dedicated.
 As a result, there are a number of dedicated server categories, like print
servers, file servers, network servers, and database servers.
 However, many servers today are shared servers which can take on the
responsibility of e-mail, DNS, FTP, and even multiple websites in the case of
a web server.
 Because they are commonly used to deliver services that are required
constantly, most servers are never turned off.
 Consequently, when servers fail, they can cause the network users and
company many problems.
 To alleviate these issues, servers are commonly high-end computers setup
to be fault tolerant.
Examples(types) of servers
 The following list contains various server types.
1. Application server
2. Blade server
3. Cloud server
4. Database server
5. Dedicated server
6. File server
7. Mail server
8. Print server
9. Proxy server
10. Standalone server
11. Web server
Application server
 The application server is a framework, an environment where applications
can run, no matter what they are or what functions they perform.
 An application server can be used to develop and run web-based
applications.
 There are a number of different types of application servers, including
Java, PHP and .NET Framework application servers.
Blade
 A blade may refer to any of the following:
1. When referring to a network router, switch, server, or other network
device, a blade(also known as an expansion module) is a
hardware component that can be installed into a chassis.
2. When talking about servers, a blade, blade server, or a high density
server is one rack mount unit that is capable of holding dozens of
different servers.
Cloud computing
 Cloud computing is a term used to describe services provided
over a network by a collection of remote servers.
 This abstract “cloud” of computers provides massive, distributed
storage and processing power, which can be accessed by any
Internet-connected device running a web browser.
 Examples of cloud services
 Amazon Web Services (AWS)
 Dashlane
 Google App Engine
 Google Calendar
 Microsoft OneDrive
 Etc..
Database Server
 A database server is a computer system that provides other
computers with services related to accessing and retrieving
data from a database.
 Access to the database server may occur via a “front end”
running locally a user‟s machine (e.g., phpMyAdmin), or
“back end” running on the database server itself, accessed
by remote shell.
 After the information within the database is retrieved it is
outputted to the user requesting the data.
Dedicated server
 A server that is hosted by a company and only allows one company to lease
and access it is called a dedicated server.
 It is “dedicated” to the one client and is not shared with any other clients.
 Dedicated servers usually allow the client to choose what operating system is
installed on it and what type of hardware.
 In most cases, the hosting company performs all or most of the maintenance on
the dedicated server. This includes:
 operating system updates
 updates to any installed applications
 monitoring of the server and applications
 firewall maintenance
 intrusion detection and prevention
 data backups
 disaster recovery
File server
 A file server is a computer on a network that is used to
provide users on a network with access to files.
Mail server
 A remote or central computer that holds electronic mail (e-mail)
messages for clients on a network is called a mail server.
 A mail server is similar to the post office, where mail is stored and
sorted before being sent to its final destination.
 When the user requests his or her e-mail, contact is established with
the mail server, which then delivers all stored to the client‟s computer.
Print server
 Computer or standalone device responsible for managing
one or more printers on a network.
 Because of the load required for a print job, a print
server does not need to be a fast computer.
 The picture is an example of a wireless standalone print
server from Cisco.
Proxy server
 A proxy is a computer server or software program that is part of
the gateway server or another computer that separates a local
network from outside networks.
 A proxy server will cache all pages accessed through the network
allowing users who may want to visit that same page to load it faster
and reduce the networks bandwidth.
 When a page is accessed that is not in the proxy server‟s cache, the
proxy server accesses the page using its own IP address, caches the
page, and forward it to the user.
SAS
 SAS may refer to any of the following:
 Short for Serial Attached SCSI, SASis a serial transmission replacement
for the parallel SCSI. SAS is an improvement of regular SCSI in that it
allow up to 128 devices to be connected at the same time with
transmission speeds of 3.0 Gb/s. SAS devices have two data ports and
can communicate with both SCSI and SATA.
 Short for Standalone Server, SASis a server that does not rely on any
other servers or services.
 Abbreviation sometimes used to describe SUPER Anti Spyware.
Web server
 Computer or collection of computers used to deliver web pages
and other content to multiple users.
 Below are some examples of web server software.
 Apache HTTP Server
 Apache Tomcat
 Microsoft IIS
 LAMP
 FastCGI
 LIGHTTPD
 XAMP
What is PHP(7.3)??
 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
 It is powerful enough to be at the core of the biggest blogging system on the
web (WordPress)!
 It is deep enough to run the largest social network (Facebook)!
Components of PHP
 To develop and run PHP Web pages three vital components need to be installed.
 Web Server
 Database
 PHP Parser
HTML v/s PHP
 How it differs from HTML
 differentiates PHP with client-side language like HTML is, PHP codes are executed on
server whereas HTML codes are directly rendered on the browser. PHP codes are first
executed on the server and then the result is returned to the browser.
Characteristics of PHP
 Simplicity
 Efficiency
 Security
 Flexibility
 Familiarity
 Inter-operable(php in html, html in php)
 PHP is whitespace insensitive
 PHP is case sensitive
Application of PHP
 PHP can generate dynamic page content
 PHP can create, open, read, write, delete, and close files on the server
 PHP can collect form data
 PHP can send and receive cookies
 PHP can add, delete, modify data in your database
 PHP can be used to control user-access
 PHP can encrypt data
Basic PHP
 Basic PHP Syntax

 // This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
Variables in PHP
 Creating (Declaring) PHP Variables
 <?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
 Rules for PHP variables:
 A variable starts with the $ sign, followed by the name of the variable
 A variable name must start with a letter or the underscore character
 A variable name cannot start with a number
 A variable name can only contain alpha-numeric characters and underscores (A-z, 0-
9, and _ )
 Variable names are case-sensitive ($age and $AGE are two different variables)
Constant in PHP
 There is no need to write a dollar sign ($) before a constant, where as in Variable
one has to write a dollar sign.
 Constants cannot be defined by simple assignment, they may only be defined
using the define() function.
 Constants may be defined and accessed anywhere without regard to variable
scoping rules.
 Once the Constants have been set, may not be redefined or undefined.
 <?php
define("MINSIZE", 50);
echo MINSIZE;
?>
Example of Variable
 <?php
$txt = “How are you?";
echo “Hello, " . $txt . "!";
?>
 Output: Hello, How are you?
 <?php
$txt = “How are you?";
echo “Hello, $txt !";
?>
 Output: ?
PHP Variables Scope
 PHP has three different variable scopes:
 local
 global
 static
 PHP The global Keyword
 global $x, $y;
 $GLOBALS[index] Array
 $GLOBALS['y'],
 $GLOBALS[„x']
 PHP The static Keyword
 static $x;
PHP echo & Print
 The PHP echo Statement
 echo or echo()
 The PHP print Statement
 print or print()
 echo has no return value while print has a return value of 1 so it can be used in
expressions.
 echo can take multiple parameters (although such usage is rare) while print can
take one argument.
 echo is marginally faster than print.
PHP Data Types
 PHP supports the following data types:
 String
 Integer
 Float (floating point numbers - also called double)
 Boolean
 Array
 Object
 NULL
 Resource
PHP Class & Object
 <?php
class Car {
function Car() {
$this->model = “Ferrari";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?>
PHP 5 Strings
 Length of a String
 strlen("Hello world!"); // outputs 12
 Number of Words in a String
 str_word_count("Hello world!"); // outputs 2
 Reverse a String
 strrev("Hello world!"); // outputs !dlrow olleH
 Search For a Specific Text Within a String
 strpos("Hello world!", "world"); // outputs 6
 Replace Text Within a String
 str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
PHP Constants
 define(name, value, case-insensitive)
 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
 <?php
define("GREETING", "Welcome to CHARUSAT!");
echo GREETING;
?>
PHP Operators
 PHP divides the operators in the following groups:
 Arithmetic operators
 Assignment operators
 Comparison operators
 Increment/Decrement operators
 Logical operators
 String operators
 Array operators
PHP Arithmetic Operators
Operator Name Example Result
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y Remainder of $x divided by $y
** Exponentiation $x ** $y Result of raising $x to the $y'th power
(Introduced in PHP 5.6)
PHP Assignment Operators
Assignment Same as... Description
x = y x = y The left operand gets set to the value of the
expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
PHP Comparison Operators
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y Returns true if $x is equal to $y,
and they are of the same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y Returns true if $x is not equal to $y,
or they are not of the same type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>= Greater than
or equal to
$x >= $y Returns true if $x is greater than
or equal to $y
<= Less than
or equal to
$x <= $y Returns true if $x is less than
or equal to $y
PHP Increment / Decrement
Operators
Operator Name Description
++$x Pre-increment Increments $x by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one
PHP Logical Operators
Operator Name Example Result
and And $x and $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y True if either $x or $y is true, but not both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true
PHP String Operators
Operator Name Example Result
. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2
.= Concatenation
assignment
$txt1 .= $txt2 Appends $txt2 to $txt1
PHP Array Operators
Operator Name Example Result
+ Union $x + $y Union of $x and $y
== Equality $x == $y Returns true if $x and $y have the
same key/value pairs
=== Identity $x === $y Returns true if $x and $y have the
same key/value pairs in the same
order and of the same types
!= Inequality $x != $y Returns true if $x is not equal to $y
<> Inequality $x <> $y Returns true if $x is not equal to $y
!== Non-identity $x !== $y Returns true if $x is not identical to $y
PHP Conditional Statements
 In PHP we have the following conditional statements:
 if statement - executes some code only if a specified condition is true
 if...else statement - executes some code if a condition is true and another code if the
condition is false
 if...elseif....else statement - specifies a new condition to test, if the first condition is false
 switch statement - selects one of many blocks of code to be executed
If...elseif…else Statement
 <?php
$t = 12;
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
Switch Statement
 <?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, or green!";
}
?>
PHP Loops
 In PHP, we have the following looping statements:
 while - loops through a block of code as long as the specified condition is true
 do...while - loops through a block of code once, and then repeats the loop as long as
the specified condition is true
 for - loops through a block of code a specified number of times
 foreach - loops through a block of code for each element in an array
The PHP while Loop
 <?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
The PHP do...while Loop
 <?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
The PHP for Loops
 The PHP for Loop
 <?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
 The PHP foreach Loop
 <?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
PHP Functions
 PHP User Defined Functions
 A function is a block of statements that can be used repeatedly in a program.
 A function will not execute immediately when a page loads.
 A function will be executed by a call to the function.
 <?php
function writeMsg() {
echo "Hello world!";
}
writeMsg(); // call the function
?>
PHP Function Arguments
 <?php
function familyName($fname, $year) {
echo "$fname Stilinski Born in $year <br>";
}
familyName("Hege", "1975");
familyName("Stale", "1978");
familyName("Kai Jim", "1983");
?>
PHP Default Argument Value
 <?php
function setHeight($minheight = 50) {
echo "The height is : $minheight <br>";
}
setHeight(350);
setHeight(); // will use the default value of 50
setHeight(135);
setHeight(80);
?>
PHP Functions - Returning
values
 <?php
function sum($x, $y) {
$z = $x + $y;
return $z;
}
echo "5 + 10 = " . sum(5, 10) . "<br>";
echo "7 + 13 = " . sum(7, 13) . "<br>";
echo "2 + 4 = " . sum(2, 4);
?>
PHP Arrays
 In PHP, there are three types of arrays:
 Indexed arrays - Arrays with a numeric index
 Associative arrays - Arrays with named keys
 Multidimensional arrays - Arrays containing one or more arrays
PHP Indexed Arrays
 <?php
$cars = array("Volvo", "BMW", "Toyota");
OR
$cars[0] = “Volvo”;
$cars[1] = “BMW”;
$cars[2] = “Toyota”;
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
 The Length of an Array - The count() Function
 count($cars);
PHP Indexed Arrays
 <?php
$cars = array("Volvo", "BMW", "Toyota");
OR
$cars[0] = “Volvo”;
$cars[1] = “BMW”;
$cars[2] = “Toyota”;
$arrlength = count($cars);
for($x = 0; $x < $arrlength; $x++) {
echo $cars[$x];
echo "<br>";
}
?>
PHP Associative Arrays
 <?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Peter is " . $age['Peter'] . " years old.";
?>
 <?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
PHP Multidimensional Arrays
 <?php
$contacts = array(
array( "name" => "Peter Parker", "email" => "peterparker@mail.com", ),
array( "name" => "Clark Kent", "email" => "clarkkent@mail.com", ),
array( "name" => "Harry Potter", "email" => "harrypotter@mail.com", ) );
echo "Peter Parker's Email-id is: " . $contacts[0]["email"];
print_r($contact);
var_dump($cities);
PHP Multidimensional Arrays
 $favorites = array(
"Dave Punk" => array(
"mob" => "5689741523",
"email" => "davepunk@gmail.com",
),
"Dave Punk" => array(
"mob" => "2584369721",
"email" => "montysmith@gmail.com",
),
"John Flinch" => array(
"mob" => "9875147536",
"email" => "johnflinch@gmail.com",
)
);
keys = array_keys($favorites);
for($i = 0; $i < count($favorites); $i++)
{
echo $keys[$i] . "n";
foreach($favorites[$keys[$i]] as $key => $value) {
echo $key . " : " . $value . "n";
}
echo "n";
}
PHP Include & Require
 The include (or require) statement takes all the text/code/markup that exists in
the specified file and copies it into the file that uses the include statement.
 It is possible to insert the content of one PHP file into another PHP file
 The include and require statements are identical, except upon failure:
 require will produce a fatal error (E_COMPILE_ERROR) and stop the script
 include will only produce a warning (E_WARNING) and the script will continue
PHP Include & Require
 Footer.php
 <?php
echo "<p>Copyright &copy; 2017-" . date("Y") . " charusat.ac.in</p>";
?>
 Index.php/home.php/dept.php
 <html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>
</body>
</html>
PHP Handling Form input
 GET v/s POST Method
 $_GET, $_POST, $_REQUEST

Contenu connexe

Tendances

Apache server configuration & optimization
Apache server configuration & optimizationApache server configuration & optimization
Apache server configuration & optimization
Gokul Muralidharan
 
Linux Apache Php Mysql Lamp1273
Linux Apache Php Mysql Lamp1273Linux Apache Php Mysql Lamp1273
Linux Apache Php Mysql Lamp1273
hussulinux
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guide
webhostingguy
 
Apache web server
Apache web serverApache web server
Apache web server
zrstoppe
 
Web Servers: Architecture and Security
Web Servers: Architecture and SecurityWeb Servers: Architecture and Security
Web Servers: Architecture and Security
george.james
 

Tendances (20)

Web servers
Web serversWeb servers
Web servers
 
PHP Training: Module 1
PHP Training: Module 1PHP Training: Module 1
PHP Training: Module 1
 
Apache Web Server Setup 4
Apache Web Server Setup 4Apache Web Server Setup 4
Apache Web Server Setup 4
 
Web Server - Internet Applications
Web Server - Internet ApplicationsWeb Server - Internet Applications
Web Server - Internet Applications
 
Apache ppt
Apache pptApache ppt
Apache ppt
 
Apache web server tutorial for linux
Apache web server tutorial for linuxApache web server tutorial for linux
Apache web server tutorial for linux
 
Apache server configuration & optimization
Apache server configuration & optimizationApache server configuration & optimization
Apache server configuration & optimization
 
Apache
ApacheApache
Apache
 
web server
web serverweb server
web server
 
Securing Your Web Server
Securing Your Web ServerSecuring Your Web Server
Securing Your Web Server
 
Linux Apache Php Mysql Lamp1273
Linux Apache Php Mysql Lamp1273Linux Apache Php Mysql Lamp1273
Linux Apache Php Mysql Lamp1273
 
Ajax
AjaxAjax
Ajax
 
Web Server-Side Programming Techniques
Web Server-Side Programming TechniquesWeb Server-Side Programming Techniques
Web Server-Side Programming Techniques
 
Apache Web server Complete Guide
Apache Web server Complete GuideApache Web server Complete Guide
Apache Web server Complete Guide
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Apache web server
Apache web serverApache web server
Apache web server
 
Web Servers: Architecture and Security
Web Servers: Architecture and SecurityWeb Servers: Architecture and Security
Web Servers: Architecture and Security
 
Apache
ApacheApache
Apache
 
Apache Tutorial
Apache TutorialApache Tutorial
Apache Tutorial
 
Web server
Web serverWeb server
Web server
 

Similaire à 4 Basic PHP

Lecture 1 Introduction to Web Development.pptx
Lecture 1 Introduction to Web Development.pptxLecture 1 Introduction to Web Development.pptx
Lecture 1 Introduction to Web Development.pptx
Kevi20
 
Ch 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet ServersCh 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet Servers
webhostingguy
 
Nadhiya lamp
Nadhiya lampNadhiya lamp
Nadhiya lamp
Nadhi ya
 

Similaire à 4 Basic PHP (20)

Server and Its Types - Presentation
Server and Its Types - PresentationServer and Its Types - Presentation
Server and Its Types - Presentation
 
Web hosting presentations by hostindia.net
Web hosting presentations by hostindia.netWeb hosting presentations by hostindia.net
Web hosting presentations by hostindia.net
 
Lecture 1 Introduction to Web Development.pptx
Lecture 1 Introduction to Web Development.pptxLecture 1 Introduction to Web Development.pptx
Lecture 1 Introduction to Web Development.pptx
 
What is Web Server & It's Types.pdf
What is Web Server & It's Types.pdfWhat is Web Server & It's Types.pdf
What is Web Server & It's Types.pdf
 
Web Server And Database Server
Web Server And Database ServerWeb Server And Database Server
Web Server And Database Server
 
webhostlecture (1).ppt
webhostlecture (1).pptwebhostlecture (1).ppt
webhostlecture (1).ppt
 
webhostlecture (1).ppt
webhostlecture (1).pptwebhostlecture (1).ppt
webhostlecture (1).ppt
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
webhost
webhostwebhost
webhost
 
Purpose and principles of web server and application server
Purpose and principles of web server and application serverPurpose and principles of web server and application server
Purpose and principles of web server and application server
 
AI using Web Design
AI using Web DesignAI using Web Design
AI using Web Design
 
WP Chap 1 & 2.pptx
WP Chap 1 & 2.pptxWP Chap 1 & 2.pptx
WP Chap 1 & 2.pptx
 
Survey of client tools
Survey of client toolsSurvey of client tools
Survey of client tools
 
Spider Course Day 1
Spider Course Day 1Spider Course Day 1
Spider Course Day 1
 
PHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHPPHP Unit-1 Introduction to PHP
PHP Unit-1 Introduction to PHP
 
Ch 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet ServersCh 22: Web Hosting and Internet Servers
Ch 22: Web Hosting and Internet Servers
 
Server Side Programming
Server Side ProgrammingServer Side Programming
Server Side Programming
 
Nadhiya lamp
Nadhiya lampNadhiya lamp
Nadhiya lamp
 
Basic Lecture on Domains and Webhosting
Basic Lecture on Domains and WebhostingBasic Lecture on Domains and Webhosting
Basic Lecture on Domains and Webhosting
 
introduction on server.pptx
introduction on server.pptxintroduction on server.pptx
introduction on server.pptx
 

Plus de Jalpesh Vasa

Plus de Jalpesh Vasa (15)

Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
 
5. HTML5
5. HTML55. HTML5
5. HTML5
 
4.4 PHP Session
4.4 PHP Session4.4 PHP Session
4.4 PHP Session
 
4.3 MySQL + PHP
4.3 MySQL + PHP4.3 MySQL + PHP
4.3 MySQL + PHP
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
4.1 PHP Arrays
4.1 PHP Arrays4.1 PHP Arrays
4.1 PHP Arrays
 
3.2.1 javascript regex example
3.2.1 javascript regex example3.2.1 javascript regex example
3.2.1 javascript regex example
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
3. Java Script
3. Java Script3. Java Script
3. Java Script
 
3.1 javascript objects_DOM
3.1 javascript objects_DOM3.1 javascript objects_DOM
3.1 javascript objects_DOM
 
2 introduction css
2 introduction css2 introduction css
2 introduction css
 
1 web technologies
1 web technologies1 web technologies
1 web technologies
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
Kotlin for android development
Kotlin for android developmentKotlin for android development
Kotlin for android development
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

4 Basic PHP

  • 2. Content  What is Server?  Types of servers.  Basic PHP.  Syntax of PHP.  Variables.  Operators.  Conditional Statements.  Loops.  PHP Function.  PHP Array & It‟s types.
  • 3.
  • 4. What is Server ?  In a technical sense, a server is an instance of a computer program that accepts and responds to requests made by another program, known as a client.  Less formally, any device that runs server software could be considered a server as well.  Servers are used to manage network resources.  For example, a user may setup a server to control access to a network, send/receive e-mail, manage print jobs, or host a website.
  • 5. What is Server ? (cont.)  Some servers are committed to a specific task, often referred to as dedicated.  As a result, there are a number of dedicated server categories, like print servers, file servers, network servers, and database servers.  However, many servers today are shared servers which can take on the responsibility of e-mail, DNS, FTP, and even multiple websites in the case of a web server.  Because they are commonly used to deliver services that are required constantly, most servers are never turned off.  Consequently, when servers fail, they can cause the network users and company many problems.  To alleviate these issues, servers are commonly high-end computers setup to be fault tolerant.
  • 6. Examples(types) of servers  The following list contains various server types. 1. Application server 2. Blade server 3. Cloud server 4. Database server 5. Dedicated server 6. File server 7. Mail server 8. Print server 9. Proxy server 10. Standalone server 11. Web server
  • 7. Application server  The application server is a framework, an environment where applications can run, no matter what they are or what functions they perform.  An application server can be used to develop and run web-based applications.  There are a number of different types of application servers, including Java, PHP and .NET Framework application servers.
  • 8. Blade  A blade may refer to any of the following: 1. When referring to a network router, switch, server, or other network device, a blade(also known as an expansion module) is a hardware component that can be installed into a chassis. 2. When talking about servers, a blade, blade server, or a high density server is one rack mount unit that is capable of holding dozens of different servers.
  • 9. Cloud computing  Cloud computing is a term used to describe services provided over a network by a collection of remote servers.  This abstract “cloud” of computers provides massive, distributed storage and processing power, which can be accessed by any Internet-connected device running a web browser.  Examples of cloud services  Amazon Web Services (AWS)  Dashlane  Google App Engine  Google Calendar  Microsoft OneDrive  Etc..
  • 10. Database Server  A database server is a computer system that provides other computers with services related to accessing and retrieving data from a database.  Access to the database server may occur via a “front end” running locally a user‟s machine (e.g., phpMyAdmin), or “back end” running on the database server itself, accessed by remote shell.  After the information within the database is retrieved it is outputted to the user requesting the data.
  • 11. Dedicated server  A server that is hosted by a company and only allows one company to lease and access it is called a dedicated server.  It is “dedicated” to the one client and is not shared with any other clients.  Dedicated servers usually allow the client to choose what operating system is installed on it and what type of hardware.  In most cases, the hosting company performs all or most of the maintenance on the dedicated server. This includes:  operating system updates  updates to any installed applications  monitoring of the server and applications  firewall maintenance  intrusion detection and prevention  data backups  disaster recovery
  • 12. File server  A file server is a computer on a network that is used to provide users on a network with access to files.
  • 13. Mail server  A remote or central computer that holds electronic mail (e-mail) messages for clients on a network is called a mail server.  A mail server is similar to the post office, where mail is stored and sorted before being sent to its final destination.  When the user requests his or her e-mail, contact is established with the mail server, which then delivers all stored to the client‟s computer.
  • 14. Print server  Computer or standalone device responsible for managing one or more printers on a network.  Because of the load required for a print job, a print server does not need to be a fast computer.  The picture is an example of a wireless standalone print server from Cisco.
  • 15. Proxy server  A proxy is a computer server or software program that is part of the gateway server or another computer that separates a local network from outside networks.  A proxy server will cache all pages accessed through the network allowing users who may want to visit that same page to load it faster and reduce the networks bandwidth.  When a page is accessed that is not in the proxy server‟s cache, the proxy server accesses the page using its own IP address, caches the page, and forward it to the user.
  • 16. SAS  SAS may refer to any of the following:  Short for Serial Attached SCSI, SASis a serial transmission replacement for the parallel SCSI. SAS is an improvement of regular SCSI in that it allow up to 128 devices to be connected at the same time with transmission speeds of 3.0 Gb/s. SAS devices have two data ports and can communicate with both SCSI and SATA.  Short for Standalone Server, SASis a server that does not rely on any other servers or services.  Abbreviation sometimes used to describe SUPER Anti Spyware.
  • 17. Web server  Computer or collection of computers used to deliver web pages and other content to multiple users.  Below are some examples of web server software.  Apache HTTP Server  Apache Tomcat  Microsoft IIS  LAMP  FastCGI  LIGHTTPD  XAMP
  • 18. What is PHP(7.3)??  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  It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)!  It is deep enough to run the largest social network (Facebook)!
  • 19. Components of PHP  To develop and run PHP Web pages three vital components need to be installed.  Web Server  Database  PHP Parser HTML v/s PHP  How it differs from HTML  differentiates PHP with client-side language like HTML is, PHP codes are executed on server whereas HTML codes are directly rendered on the browser. PHP codes are first executed on the server and then the result is returned to the browser.
  • 20. Characteristics of PHP  Simplicity  Efficiency  Security  Flexibility  Familiarity  Inter-operable(php in html, html in php)  PHP is whitespace insensitive  PHP is case sensitive
  • 21. Application of PHP  PHP can generate dynamic page content  PHP can create, open, read, write, delete, and close files on the server  PHP can collect form data  PHP can send and receive cookies  PHP can add, delete, modify data in your database  PHP can be used to control user-access  PHP can encrypt data
  • 22. Basic PHP  Basic PHP Syntax   // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */
  • 23. Variables in PHP  Creating (Declaring) PHP Variables  <?php $txt = "Hello world!"; $x = 5; $y = 10.5; ?>  Rules for PHP variables:  A variable starts with the $ sign, followed by the name of the variable  A variable name must start with a letter or the underscore character  A variable name cannot start with a number  A variable name can only contain alpha-numeric characters and underscores (A-z, 0- 9, and _ )  Variable names are case-sensitive ($age and $AGE are two different variables)
  • 24. Constant in PHP  There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign.  Constants cannot be defined by simple assignment, they may only be defined using the define() function.  Constants may be defined and accessed anywhere without regard to variable scoping rules.  Once the Constants have been set, may not be redefined or undefined.  <?php define("MINSIZE", 50); echo MINSIZE; ?>
  • 25. Example of Variable  <?php $txt = “How are you?"; echo “Hello, " . $txt . "!"; ?>  Output: Hello, How are you?  <?php $txt = “How are you?"; echo “Hello, $txt !"; ?>  Output: ?
  • 26. PHP Variables Scope  PHP has three different variable scopes:  local  global  static  PHP The global Keyword  global $x, $y;  $GLOBALS[index] Array  $GLOBALS['y'],  $GLOBALS[„x']  PHP The static Keyword  static $x;
  • 27. PHP echo & Print  The PHP echo Statement  echo or echo()  The PHP print Statement  print or print()  echo has no return value while print has a return value of 1 so it can be used in expressions.  echo can take multiple parameters (although such usage is rare) while print can take one argument.  echo is marginally faster than print.
  • 28. PHP Data Types  PHP supports the following data types:  String  Integer  Float (floating point numbers - also called double)  Boolean  Array  Object  NULL  Resource
  • 29. PHP Class & Object  <?php class Car { function Car() { $this->model = “Ferrari"; } } // create an object $herbie = new Car(); // show object properties echo $herbie->model; ?>
  • 30. PHP 5 Strings  Length of a String  strlen("Hello world!"); // outputs 12  Number of Words in a String  str_word_count("Hello world!"); // outputs 2  Reverse a String  strrev("Hello world!"); // outputs !dlrow olleH  Search For a Specific Text Within a String  strpos("Hello world!", "world"); // outputs 6  Replace Text Within a String  str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
  • 31. PHP Constants  define(name, value, case-insensitive)  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  <?php define("GREETING", "Welcome to CHARUSAT!"); echo GREETING; ?>
  • 32. PHP Operators  PHP divides the operators in the following groups:  Arithmetic operators  Assignment operators  Comparison operators  Increment/Decrement operators  Logical operators  String operators  Array operators
  • 33. PHP Arithmetic Operators Operator Name Example Result + Addition $x + $y Sum of $x and $y - Subtraction $x - $y Difference of $x and $y * Multiplication $x * $y Product of $x and $y / Division $x / $y Quotient of $x and $y % Modulus $x % $y Remainder of $x divided by $y ** Exponentiation $x ** $y Result of raising $x to the $y'th power (Introduced in PHP 5.6)
  • 34. PHP Assignment Operators Assignment Same as... Description x = y x = y The left operand gets set to the value of the expression on the right x += y x = x + y Addition x -= y x = x - y Subtraction x *= y x = x * y Multiplication x /= y x = x / y Division x %= y x = x % y Modulus
  • 35. PHP Comparison Operators Operator Name Example Result == Equal $x == $y Returns true if $x is equal to $y === Identical $x === $y Returns true if $x is equal to $y, and they are of the same type != Not equal $x != $y Returns true if $x is not equal to $y <> Not equal $x <> $y Returns true if $x is not equal to $y !== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type > Greater than $x > $y Returns true if $x is greater than $y < Less than $x < $y Returns true if $x is less than $y >= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y <= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
  • 36. PHP Increment / Decrement Operators Operator Name Description ++$x Pre-increment Increments $x by one, then returns $x $x++ Post-increment Returns $x, then increments $x by one --$x Pre-decrement Decrements $x by one, then returns $x $x-- Post-decrement Returns $x, then decrements $x by one
  • 37. PHP Logical Operators Operator Name Example Result and And $x and $y True if both $x and $y are true or Or $x or $y True if either $x or $y is true xor Xor $x xor $y True if either $x or $y is true, but not both && And $x && $y True if both $x and $y are true || Or $x || $y True if either $x or $y is true ! Not !$x True if $x is not true
  • 38. PHP String Operators Operator Name Example Result . Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2 .= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1
  • 39. PHP Array Operators Operator Name Example Result + Union $x + $y Union of $x and $y == Equality $x == $y Returns true if $x and $y have the same key/value pairs === Identity $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types != Inequality $x != $y Returns true if $x is not equal to $y <> Inequality $x <> $y Returns true if $x is not equal to $y !== Non-identity $x !== $y Returns true if $x is not identical to $y
  • 40. PHP Conditional Statements  In PHP we have the following conditional statements:  if statement - executes some code only if a specified condition is true  if...else statement - executes some code if a condition is true and another code if the condition is false  if...elseif....else statement - specifies a new condition to test, if the first condition is false  switch statement - selects one of many blocks of code to be executed
  • 41. If...elseif…else Statement  <?php $t = 12; if ($t < "10") { echo "Have a good morning!"; } elseif ($t < "20") { echo "Have a good day!"; } else { echo "Have a good night!"; } ?>
  • 42. Switch Statement  <?php $favcolor = "red"; switch ($favcolor) { case "red": echo "Your favorite color is red!"; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, or green!"; } ?>
  • 43. PHP Loops  In PHP, we have the following looping statements:  while - loops through a block of code as long as the specified condition is true  do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true  for - loops through a block of code a specified number of times  foreach - loops through a block of code for each element in an array
  • 44. The PHP while Loop  <?php $x = 1; while($x <= 5) { echo "The number is: $x <br>"; $x++; } ?>
  • 45. The PHP do...while Loop  <?php $x = 1; do { echo "The number is: $x <br>"; $x++; } while ($x <= 5); ?>
  • 46. The PHP for Loops  The PHP for Loop  <?php for ($x = 0; $x <= 10; $x++) { echo "The number is: $x <br>"; } ?>  The PHP foreach Loop  <?php $colors = array("red", "green", "blue", "yellow"); foreach ($colors as $value) { echo "$value <br>"; } ?>
  • 47. PHP Functions  PHP User Defined Functions  A function is a block of statements that can be used repeatedly in a program.  A function will not execute immediately when a page loads.  A function will be executed by a call to the function.  <?php function writeMsg() { echo "Hello world!"; } writeMsg(); // call the function ?>
  • 48. PHP Function Arguments  <?php function familyName($fname, $year) { echo "$fname Stilinski Born in $year <br>"; } familyName("Hege", "1975"); familyName("Stale", "1978"); familyName("Kai Jim", "1983"); ?>
  • 49. PHP Default Argument Value  <?php function setHeight($minheight = 50) { echo "The height is : $minheight <br>"; } setHeight(350); setHeight(); // will use the default value of 50 setHeight(135); setHeight(80); ?>
  • 50. PHP Functions - Returning values  <?php function sum($x, $y) { $z = $x + $y; return $z; } echo "5 + 10 = " . sum(5, 10) . "<br>"; echo "7 + 13 = " . sum(7, 13) . "<br>"; echo "2 + 4 = " . sum(2, 4); ?>
  • 51. PHP Arrays  In PHP, there are three types of arrays:  Indexed arrays - Arrays with a numeric index  Associative arrays - Arrays with named keys  Multidimensional arrays - Arrays containing one or more arrays
  • 52. PHP Indexed Arrays  <?php $cars = array("Volvo", "BMW", "Toyota"); OR $cars[0] = “Volvo”; $cars[1] = “BMW”; $cars[2] = “Toyota”; echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . "."; ?>  The Length of an Array - The count() Function  count($cars);
  • 53. PHP Indexed Arrays  <?php $cars = array("Volvo", "BMW", "Toyota"); OR $cars[0] = “Volvo”; $cars[1] = “BMW”; $cars[2] = “Toyota”; $arrlength = count($cars); for($x = 0; $x < $arrlength; $x++) { echo $cars[$x]; echo "<br>"; } ?>
  • 54. PHP Associative Arrays  <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); echo "Peter is " . $age['Peter'] . " years old."; ?>  <?php $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); foreach($age as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } ?>
  • 55. PHP Multidimensional Arrays  <?php $contacts = array( array( "name" => "Peter Parker", "email" => "peterparker@mail.com", ), array( "name" => "Clark Kent", "email" => "clarkkent@mail.com", ), array( "name" => "Harry Potter", "email" => "harrypotter@mail.com", ) ); echo "Peter Parker's Email-id is: " . $contacts[0]["email"]; print_r($contact); var_dump($cities);
  • 56. PHP Multidimensional Arrays  $favorites = array( "Dave Punk" => array( "mob" => "5689741523", "email" => "davepunk@gmail.com", ), "Dave Punk" => array( "mob" => "2584369721", "email" => "montysmith@gmail.com", ), "John Flinch" => array( "mob" => "9875147536", "email" => "johnflinch@gmail.com", ) ); keys = array_keys($favorites); for($i = 0; $i < count($favorites); $i++) { echo $keys[$i] . "n"; foreach($favorites[$keys[$i]] as $key => $value) { echo $key . " : " . $value . "n"; } echo "n"; }
  • 57. PHP Include & Require  The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.  It is possible to insert the content of one PHP file into another PHP file  The include and require statements are identical, except upon failure:  require will produce a fatal error (E_COMPILE_ERROR) and stop the script  include will only produce a warning (E_WARNING) and the script will continue
  • 58. PHP Include & Require  Footer.php  <?php echo "<p>Copyright &copy; 2017-" . date("Y") . " charusat.ac.in</p>"; ?>  Index.php/home.php/dept.php  <html> <body> <h1>Welcome to my home page!</h1> <p>Some text.</p> <p>Some more text.</p> <?php include 'footer.php';?> </body> </html>
  • 59. PHP Handling Form input  GET v/s POST Method  $_GET, $_POST, $_REQUEST