SlideShare ist ein Scribd-Unternehmen logo
1 von 32
PHP
Why should we learn web programming?
No need write socket programming.
- You can forget TCP/IP & OSI layers.
- Web server handles socket tasks for us.
Why should we learn web programming?
• Ability to develop variety of systems, intranet &
extranet.
• - Inventory control system.
• - Accounting application.
• - Financial Analysis tools.
• - Portal website.
• - E-Commerce website.
• - Game on facebook.
• - etc.
HTTP is about Request / Response.
What programs are inside web server?
• Operating System such as Windows, Fedora, Ubuntu.
- Handles communications between tenant
programs(programs that run on top of OS) and
machine.
• Web Server Program such as Apache, IIS
- Listening for request which is come from web browser
on port 80. (Normally HTTP port)
- Send response back to web browser.
• Language extension such as PHP, Perl, Python, Ruby.
- Binding to Web Server Program.
- Processing request, response and data from database.
What programs are inside
Database server?
• Operating System such as Windows, Fedora, Ubuntu.
- Handles communications between tenant
programs(programs that run on top of OS) and
machine.
• Database Server Program such as MySQL, Oracle.
- Listening for query (Command) which is come from
WebServer on port 3306. (Normally MySQL port)
- Send data back or update data itself.
• We can install Database Server Program inside the
samemachine as Web Server but it is not
recommended.
Why PHP & MySQL?
• Popular stack people use all over the world so
when you get stuck you just google your
problem.
• PHP is free of charge. MySQL is also free.
• Your code can deploy on both Windows and
Linux servers.
• Most web hosting services support.
• Coding PHP is fast and easy.
• MySQL is quite stable and fast. (For large scale of
datas you have to use some techniques to
optimize it)
PHP (PHP: Hypertext Preprocessor)
PHP is a server-side scripting language intended
to help web developers build dynamic web
sites quickly.
How does PHP work?
• PHP scripts are executed on the server, before
the web page is displayed to the user (this is
what we mean by "server-side"). The user
only sees the end result, which consists of
client-side markup and scripts (i.e. HTML,
JavaScript, CSS etc). Therefore, the
user/browser doesn't actually see any PHP
code. If the user views the source code, all
they would see is HTML, JavaScript, CSS etc -
they wouldn't see any PHP code.
• PHP is scripts (lines of command) which will be
executed when web server has received
REQUEST.
• After all PHP scripts completely executed, web
server will send the result (of executed) back
to web browser as RESPONSE.
PHP Coding Structure
Creating PHP file
• Pain text file (No rich text file such as a file
created with MS Word or Wordpad).
• HTML and PHP code inside.
• File has to be saved with .php extension.
Scripting blocks
• Every block of PHP code must start with <?
php and end with ?>
• <? and ?> can be used instead but some
servers are not support this style so it is better
to use <?php and ?>
• PHP blocks normally embed to HTML code to
control how HTML text should be rendered.
Semi colon ;
• You need to place a semi-colon (;) at the end
of each line of PHP code. This tells the server
that a particular statement has finished.
<!-- example1.php -->
<html>
<head>
<title>PHP Syntax Example</title>
</head>
<body>
<?php
print “PHP is Pretty Hot Programming!”;
?>
</body>
</html>
Commenting
• Use this // Comment here for single line
comment.
• Use this /* Comment
multiple
lines */
for multiple lines comment.
• Benefits to explain your idea, info, warning to
other programmers who read your code.
<?php
/*
This file name is example2.php
*/
?>
<html>
<head>
<title>PHP Syntax Example</title>
</head>
<body>
<?php
// show a cool word to visitor
print “PHP is Pretty Hot Programming!”;
print “ Isn’t it?”; // Ask visitor if they agree.
?>
</body>
</html>
Variable
• Variables are named "containers" that allow
you to store a value. This value can then be
used by other parts of the application, simply
by referring to the variable's name. For
example, the application could display the
contents of the variable to the user.
• In PHP, variable names must start with a dollar
sign ($). For example:
<?php
$myVariable = "PHP is too easy for us";
print $myVariable;
?>
Variable types
• There are 2 kinds of type: Simple and Complex
• Simple is integer, float and boolean, string.
• Complex is array type and object type.
Integer
• Integer variables are able to hold a whole
number. Negative values can be assigned by
placing the minus (-) sign after the assignment
operator and before the number.
<?php
$variable1 = -2;
$variable2 = 9;
$variable3 = $variable1 + $variable2;
print $variable3;
?>
Float
• Floating point variables contain numbers that
require the use of decimal places.
<?php
$variable1 = -4234.2233;
$variable2 = 0.0999;
$variable3 = $variable1 * $variable2;
print $variable3;
?>
Boolean
• PHP boolean type variables hold a value of true or false
and are used to test conditions such as whether some
part of a script was performed correctly.
<?php
$variable1 = true;
$variable2 = false;
$variable3 = 1;
$variable4 = 0;
$variable5 = $variable1 && $variable4;
print $variable5;
?>
String
• The string variable type is used to hold strings
of characters such as words and sentences.
• A string can be assigned to variable either by
surrounding it in single quotes (') or double
quotes ("). If your string itself contains either
single or double quotes you should use the
opposite to wrap the string:
<?php
$variable1 = “Hello Tony”;
$variable2 = ‘Hello Tony’;
$variable3 = “Hello ‘Tony’ ”;
$variable4 = ‘Hello “Tony” ’;
?>
Array
• PHP Arrays provide a way to group together
many variables such that they can be
referenced and manipulated using a single
variable. An array is list of variables.
<?php
$ar1 = array(); // Creating empty array (nothing inside)
// Create an array with various types inside
$ar2 = array(1, 2.5, ‘Dog’, false);
// Access and print value from array slot#2
print $ar2[2];
print ‘<br />’; // For visibility, add new line looks
$ar3 = array(‘A’=>80, ‘B’=>70, ‘F’=>‘Fail’);
// Access and print value from array slot named ’B’
print $ar3[‘B’];
?>
Hello.php<?php
$name1 = '';
$name2 = '';
if(isset($_GET['param1'])) $name1 = $_GET['param1'];
if(isset($_GET['param2'])) $name2 = $_GET['param2'];
?>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
Hello <?php print $name1; ?><?php if($name2 != '') print 'and
'; ?><?php print $name2; ?>!
</body>
</html>
Operators
Operator Description Example Result
+ Addition 23 + 7 30
- Subtraction 90.34 - 1.11 89.23
* Multiplication 34232.43434 * 0 0
/ Division 15 / 3 5
% Modulus (Division remainder) 10 % 3 1
++ Increment $a = 99;
++$a
100
-- Decrement $b = 50;
--$b;
49
==,!= is equal to / is not equal to 80 == 6 FALSE
> , < is greater than / is less than 7 > 3 TRUE
&& and (5==5 && 6==6) TRUE
|| or (5==5 || 6==8) FALSE
! not !(0 > 1) TRUE
. string concatenation PH’ . ‘P’ . “!” PHP!
Submitting FORM data to PHP
page
• You have 2 php files.
• p1.php is a sending page
• p2.php is a receiving page
• p1.php has FORM tag with action=”p2.php” attribute
• p1.php has input tags with name=”anyname”
attribute
• p2.php has php code to get datas which will be
submitted from p1.php
• p2.php gets datas by referring to $_GET[‘anyname’]
// p1.php
<form action ="p2.php" method=get>
Email: <input type="text" name="mail"> <br>
Name : <input type="text" name="name" > <br>
<textarea name="comment" cols=40 rows=10></textarea>
<br>
<input type="submit" value="Submit"> </form>
// p2.php
<?php
$email = $mail;
print "Your email is " . $email. "<br>";
print " and your name is " . $name;
print ' and your comment is '. $comment;

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to XML, XHTML and CSS
Introduction to XML, XHTML and CSSIntroduction to XML, XHTML and CSS
Introduction to XML, XHTML and CSS
Jussi Pohjolainen
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formatting
eShikshak
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
BG Java EE Course
 

Was ist angesagt? (20)

HTML
HTMLHTML
HTML
 
Web development using html 5
Web development using html 5Web development using html 5
Web development using html 5
 
Introduction to XML, XHTML and CSS
Introduction to XML, XHTML and CSSIntroduction to XML, XHTML and CSS
Introduction to XML, XHTML and CSS
 
HTML 5 Step By Step - Ebook
HTML 5 Step By Step - EbookHTML 5 Step By Step - Ebook
HTML 5 Step By Step - Ebook
 
HTML Lists & Llinks
HTML Lists & LlinksHTML Lists & Llinks
HTML Lists & Llinks
 
Web I - 02 - XHTML Introduction
Web I - 02 - XHTML IntroductionWeb I - 02 - XHTML Introduction
Web I - 02 - XHTML Introduction
 
Html Workshop
Html WorkshopHtml Workshop
Html Workshop
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formatting
 
Session ii(html)
Session ii(html)Session ii(html)
Session ii(html)
 
Html basic
Html basicHtml basic
Html basic
 
An SEO’s Intro to Web Dev PHP
An SEO’s Intro to Web Dev PHPAn SEO’s Intro to Web Dev PHP
An SEO’s Intro to Web Dev PHP
 
HTML By K.Sasidhar
HTML By K.SasidharHTML By K.Sasidhar
HTML By K.Sasidhar
 
How the Web Works Using HTML
How the Web Works Using HTMLHow the Web Works Using HTML
How the Web Works Using HTML
 
Html full
Html fullHtml full
Html full
 
Web page concept final ppt
Web page concept  final pptWeb page concept  final ppt
Web page concept final ppt
 
Html example
Html exampleHtml example
Html example
 
Elements of html powerpoint
Elements of html powerpointElements of html powerpoint
Elements of html powerpoint
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
 
HTML5
HTML5 HTML5
HTML5
 
Html introduction
Html introductionHtml introduction
Html introduction
 

Andere mochten auch

Observatoire de la fidélité AQUITEM/IAE Présentation 26 Mars
Observatoire de la fidélité AQUITEM/IAE Présentation 26 MarsObservatoire de la fidélité AQUITEM/IAE Présentation 26 Mars
Observatoire de la fidélité AQUITEM/IAE Présentation 26 Mars
zefid
 

Andere mochten auch (13)

03 businessfinance v1
03 businessfinance v103 businessfinance v1
03 businessfinance v1
 
[En] MIB Dauphine - ICT6
[En] MIB Dauphine - ICT6[En] MIB Dauphine - ICT6
[En] MIB Dauphine - ICT6
 
RIS Cont. Store
RIS Cont. StoreRIS Cont. Store
RIS Cont. Store
 
Lean Local Government: Using Lean Startup Principles to Empower Government Em...
Lean Local Government: Using Lean Startup Principles to Empower Government Em...Lean Local Government: Using Lean Startup Principles to Empower Government Em...
Lean Local Government: Using Lean Startup Principles to Empower Government Em...
 
Observatoire de la créativité 2016
Observatoire de la créativité 2016Observatoire de la créativité 2016
Observatoire de la créativité 2016
 
Customer Development Power-Ups
Customer Development Power-UpsCustomer Development Power-Ups
Customer Development Power-Ups
 
Caution: Live Subjects! Lean Experiments for Services
Caution: Live Subjects! Lean Experiments for ServicesCaution: Live Subjects! Lean Experiments for Services
Caution: Live Subjects! Lean Experiments for Services
 
การบริหารเงินทุนหมุนเวียน
การบริหารเงินทุนหมุนเวียนการบริหารเงินทุนหมุนเวียน
การบริหารเงินทุนหมุนเวียน
 
Observatoire de la fidélité AQUITEM/IAE Présentation 26 Mars
Observatoire de la fidélité AQUITEM/IAE Présentation 26 MarsObservatoire de la fidélité AQUITEM/IAE Présentation 26 Mars
Observatoire de la fidélité AQUITEM/IAE Présentation 26 Mars
 
การพยากรณ์และการวางแผนทางการเงิน
การพยากรณ์และการวางแผนทางการเงินการพยากรณ์และการวางแผนทางการเงิน
การพยากรณ์และการวางแผนทางการเงิน
 
บทที่ 4 การพยากรณ์
บทที่ 4 การพยากรณ์บทที่ 4 การพยากรณ์
บทที่ 4 การพยากรณ์
 
DAAT DAY : Digital Trend Spotting 2016 & Implication For Brand
DAAT DAY :  Digital Trend Spotting 2016 & Implication For BrandDAAT DAY :  Digital Trend Spotting 2016 & Implication For Brand
DAAT DAY : Digital Trend Spotting 2016 & Implication For Brand
 
Lawyers and Social Media in 2016
Lawyers and Social Media in 2016Lawyers and Social Media in 2016
Lawyers and Social Media in 2016
 

Ähnlich wie php 1

Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
ShaimaaMohamedGalal
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Muhamad Al Imran
 

Ähnlich wie php 1 (20)

Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 
PHP
PHPPHP
PHP
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
LAB PHP Consolidated.ppt
LAB PHP Consolidated.pptLAB PHP Consolidated.ppt
LAB PHP Consolidated.ppt
 
Php unit i
Php unit iPhp unit i
Php unit i
 
Php
PhpPhp
Php
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Prersentation
PrersentationPrersentation
Prersentation
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
 
Lecture8
Lecture8Lecture8
Lecture8
 
PHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginnersPHP complete reference with database concepts for beginners
PHP complete reference with database concepts for beginners
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
INTRODUCTION to php.pptx
INTRODUCTION to php.pptxINTRODUCTION to php.pptx
INTRODUCTION to php.pptx
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Mehr von tumetr1

ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็คตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างภาคผนวก เล่มโปรเจ็ค
ตัวอย่างภาคผนวก เล่มโปรเจ็คตัวอย่างภาคผนวก เล่มโปรเจ็ค
ตัวอย่างภาคผนวก เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
ตัวอย่างบรรณานุกรม เล่มโปรเจ็คตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
ตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็คตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างสารบัญ เล่มโปรเจ็ค
ตัวอย่างสารบัญ เล่มโปรเจ็คตัวอย่างสารบัญ เล่มโปรเจ็ค
ตัวอย่างสารบัญ เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็คตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
tumetr1
 
ระบบเครือข่ายไร้สาย (wireless lan)
ระบบเครือข่ายไร้สาย (wireless lan)ระบบเครือข่ายไร้สาย (wireless lan)
ระบบเครือข่ายไร้สาย (wireless lan)
tumetr1
 
ระดับชั้นเน็ตเวิร์ก
ระดับชั้นเน็ตเวิร์กระดับชั้นเน็ตเวิร์ก
ระดับชั้นเน็ตเวิร์ก
tumetr1
 
ระดับชั้นดาต้าลิงค์
ระดับชั้นดาต้าลิงค์ระดับชั้นดาต้าลิงค์
ระดับชั้นดาต้าลิงค์
tumetr1
 
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการสถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
tumetr1
 
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่ายการส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
tumetr1
 
ความรู้พื้นฐานของระบบการสื่อสารข้อมูล
ความรู้พื้นฐานของระบบการสื่อสารข้อมูลความรู้พื้นฐานของระบบการสื่อสารข้อมูล
ความรู้พื้นฐานของระบบการสื่อสารข้อมูล
tumetr1
 

Mehr von tumetr1 (20)

ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็คตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
 
ตัวอย่างภาคผนวก เล่มโปรเจ็ค
ตัวอย่างภาคผนวก เล่มโปรเจ็คตัวอย่างภาคผนวก เล่มโปรเจ็ค
ตัวอย่างภาคผนวก เล่มโปรเจ็ค
 
ตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
ตัวอย่างบรรณานุกรม เล่มโปรเจ็คตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
ตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
 
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็คตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
 
ตัวอย่างสารบัญ เล่มโปรเจ็ค
ตัวอย่างสารบัญ เล่มโปรเจ็คตัวอย่างสารบัญ เล่มโปรเจ็ค
ตัวอย่างสารบัญ เล่มโปรเจ็ค
 
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็คตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
 
ตัวอย่างบทคัดย่อเล่มโปรเจ็ค
ตัวอย่างบทคัดย่อเล่มโปรเจ็คตัวอย่างบทคัดย่อเล่มโปรเจ็ค
ตัวอย่างบทคัดย่อเล่มโปรเจ็ค
 
file transfer and access utilities
file transfer and access utilitiesfile transfer and access utilities
file transfer and access utilities
 
retrieving the mail
retrieving the mailretrieving the mail
retrieving the mail
 
connectivity utility
connectivity utilityconnectivity utility
connectivity utility
 
network hardware
network hardwarenetwork hardware
network hardware
 
ระบบเครือข่ายไร้สาย (wireless lan)
ระบบเครือข่ายไร้สาย (wireless lan)ระบบเครือข่ายไร้สาย (wireless lan)
ระบบเครือข่ายไร้สาย (wireless lan)
 
routing
routingrouting
routing
 
the transport layer
the transport layerthe transport layer
the transport layer
 
ระดับชั้นเน็ตเวิร์ก
ระดับชั้นเน็ตเวิร์กระดับชั้นเน็ตเวิร์ก
ระดับชั้นเน็ตเวิร์ก
 
ระดับชั้นดาต้าลิงค์
ระดับชั้นดาต้าลิงค์ระดับชั้นดาต้าลิงค์
ระดับชั้นดาต้าลิงค์
 
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการสถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
 
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่ายการส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
 
ความรู้พื้นฐานของระบบการสื่อสารข้อมูล
ความรู้พื้นฐานของระบบการสื่อสารข้อมูลความรู้พื้นฐานของระบบการสื่อสารข้อมูล
ความรู้พื้นฐานของระบบการสื่อสารข้อมูล
 
พัฒนาเศรษฐกิจ
พัฒนาเศรษฐกิจพัฒนาเศรษฐกิจ
พัฒนาเศรษฐกิจ
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
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
 
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
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
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 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
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
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
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 

php 1

  • 1. PHP
  • 2. Why should we learn web programming? No need write socket programming. - You can forget TCP/IP & OSI layers. - Web server handles socket tasks for us.
  • 3. Why should we learn web programming? • Ability to develop variety of systems, intranet & extranet. • - Inventory control system. • - Accounting application. • - Financial Analysis tools. • - Portal website. • - E-Commerce website. • - Game on facebook. • - etc.
  • 4. HTTP is about Request / Response.
  • 5. What programs are inside web server? • Operating System such as Windows, Fedora, Ubuntu. - Handles communications between tenant programs(programs that run on top of OS) and machine. • Web Server Program such as Apache, IIS - Listening for request which is come from web browser on port 80. (Normally HTTP port) - Send response back to web browser. • Language extension such as PHP, Perl, Python, Ruby. - Binding to Web Server Program. - Processing request, response and data from database.
  • 6. What programs are inside Database server? • Operating System such as Windows, Fedora, Ubuntu. - Handles communications between tenant programs(programs that run on top of OS) and machine. • Database Server Program such as MySQL, Oracle. - Listening for query (Command) which is come from WebServer on port 3306. (Normally MySQL port) - Send data back or update data itself. • We can install Database Server Program inside the samemachine as Web Server but it is not recommended.
  • 7. Why PHP & MySQL? • Popular stack people use all over the world so when you get stuck you just google your problem. • PHP is free of charge. MySQL is also free. • Your code can deploy on both Windows and Linux servers. • Most web hosting services support. • Coding PHP is fast and easy. • MySQL is quite stable and fast. (For large scale of datas you have to use some techniques to optimize it)
  • 8. PHP (PHP: Hypertext Preprocessor) PHP is a server-side scripting language intended to help web developers build dynamic web sites quickly.
  • 9. How does PHP work? • PHP scripts are executed on the server, before the web page is displayed to the user (this is what we mean by "server-side"). The user only sees the end result, which consists of client-side markup and scripts (i.e. HTML, JavaScript, CSS etc). Therefore, the user/browser doesn't actually see any PHP code. If the user views the source code, all they would see is HTML, JavaScript, CSS etc - they wouldn't see any PHP code.
  • 10. • PHP is scripts (lines of command) which will be executed when web server has received REQUEST. • After all PHP scripts completely executed, web server will send the result (of executed) back to web browser as RESPONSE.
  • 12. Creating PHP file • Pain text file (No rich text file such as a file created with MS Word or Wordpad). • HTML and PHP code inside. • File has to be saved with .php extension.
  • 13. Scripting blocks • Every block of PHP code must start with <? php and end with ?> • <? and ?> can be used instead but some servers are not support this style so it is better to use <?php and ?> • PHP blocks normally embed to HTML code to control how HTML text should be rendered.
  • 14. Semi colon ; • You need to place a semi-colon (;) at the end of each line of PHP code. This tells the server that a particular statement has finished.
  • 15. <!-- example1.php --> <html> <head> <title>PHP Syntax Example</title> </head> <body> <?php print “PHP is Pretty Hot Programming!”; ?> </body> </html>
  • 16. Commenting • Use this // Comment here for single line comment. • Use this /* Comment multiple lines */ for multiple lines comment. • Benefits to explain your idea, info, warning to other programmers who read your code.
  • 17. <?php /* This file name is example2.php */ ?> <html> <head> <title>PHP Syntax Example</title> </head> <body> <?php // show a cool word to visitor print “PHP is Pretty Hot Programming!”; print “ Isn’t it?”; // Ask visitor if they agree. ?> </body> </html>
  • 18. Variable • Variables are named "containers" that allow you to store a value. This value can then be used by other parts of the application, simply by referring to the variable's name. For example, the application could display the contents of the variable to the user. • In PHP, variable names must start with a dollar sign ($). For example:
  • 19. <?php $myVariable = "PHP is too easy for us"; print $myVariable; ?>
  • 20. Variable types • There are 2 kinds of type: Simple and Complex • Simple is integer, float and boolean, string. • Complex is array type and object type.
  • 21. Integer • Integer variables are able to hold a whole number. Negative values can be assigned by placing the minus (-) sign after the assignment operator and before the number.
  • 22. <?php $variable1 = -2; $variable2 = 9; $variable3 = $variable1 + $variable2; print $variable3; ?>
  • 23. Float • Floating point variables contain numbers that require the use of decimal places. <?php $variable1 = -4234.2233; $variable2 = 0.0999; $variable3 = $variable1 * $variable2; print $variable3; ?>
  • 24. Boolean • PHP boolean type variables hold a value of true or false and are used to test conditions such as whether some part of a script was performed correctly. <?php $variable1 = true; $variable2 = false; $variable3 = 1; $variable4 = 0; $variable5 = $variable1 && $variable4; print $variable5; ?>
  • 25. String • The string variable type is used to hold strings of characters such as words and sentences. • A string can be assigned to variable either by surrounding it in single quotes (') or double quotes ("). If your string itself contains either single or double quotes you should use the opposite to wrap the string:
  • 26. <?php $variable1 = “Hello Tony”; $variable2 = ‘Hello Tony’; $variable3 = “Hello ‘Tony’ ”; $variable4 = ‘Hello “Tony” ’; ?>
  • 27. Array • PHP Arrays provide a way to group together many variables such that they can be referenced and manipulated using a single variable. An array is list of variables.
  • 28. <?php $ar1 = array(); // Creating empty array (nothing inside) // Create an array with various types inside $ar2 = array(1, 2.5, ‘Dog’, false); // Access and print value from array slot#2 print $ar2[2]; print ‘<br />’; // For visibility, add new line looks $ar3 = array(‘A’=>80, ‘B’=>70, ‘F’=>‘Fail’); // Access and print value from array slot named ’B’ print $ar3[‘B’]; ?>
  • 29. Hello.php<?php $name1 = ''; $name2 = ''; if(isset($_GET['param1'])) $name1 = $_GET['param1']; if(isset($_GET['param2'])) $name2 = $_GET['param2']; ?> <html> <head> <title>Hello World!</title> </head> <body> Hello <?php print $name1; ?><?php if($name2 != '') print 'and '; ?><?php print $name2; ?>! </body> </html>
  • 30. Operators Operator Description Example Result + Addition 23 + 7 30 - Subtraction 90.34 - 1.11 89.23 * Multiplication 34232.43434 * 0 0 / Division 15 / 3 5 % Modulus (Division remainder) 10 % 3 1 ++ Increment $a = 99; ++$a 100 -- Decrement $b = 50; --$b; 49 ==,!= is equal to / is not equal to 80 == 6 FALSE > , < is greater than / is less than 7 > 3 TRUE && and (5==5 && 6==6) TRUE || or (5==5 || 6==8) FALSE ! not !(0 > 1) TRUE . string concatenation PH’ . ‘P’ . “!” PHP!
  • 31. Submitting FORM data to PHP page • You have 2 php files. • p1.php is a sending page • p2.php is a receiving page • p1.php has FORM tag with action=”p2.php” attribute • p1.php has input tags with name=”anyname” attribute • p2.php has php code to get datas which will be submitted from p1.php • p2.php gets datas by referring to $_GET[‘anyname’]
  • 32. // p1.php <form action ="p2.php" method=get> Email: <input type="text" name="mail"> <br> Name : <input type="text" name="name" > <br> <textarea name="comment" cols=40 rows=10></textarea> <br> <input type="submit" value="Submit"> </form> // p2.php <?php $email = $mail; print "Your email is " . $email. "<br>"; print " and your name is " . $name; print ' and your comment is '. $comment;