Dasar
Pertemuan ke-4
Server Side Scripting - PHP
1
Review
Perangkat Keras
Server
Perangkat Lunak
Operating System: Linux. MaxOS, Windows
Web Server: Apache, IIS
Database Server: MySQL, MSSQL
Basic SQL commands:
Create, Select, Insert, Update & Delete
2
Tujuan
3
Web Scripting
4
Client-side & Server-side
Scripting (similar)
7
JavaScript
<script type=”text/javascript”>
<!--
document.writeln('<h1>Welcome</h1>');
-->
</script>
8
JavaScript Sebagai Client-Side
Keuntungan:
Dapat digunakan langsung dalam berinteraksi
dengan web browser
Sebagai salah satu teknologi yang diperlukan dalam
pembuatan AJAX
Kerugian:
Source code dapat dilihat, walaupun ada teknik
tertentu untuk mencegahnya
Tidak bisa melakukan koneksi langsung ke database
9
VBScript
10
Server-Side Scripting
11
Server-Side Scripting
(Keuntungan 1)
No browser compability issues. PHP script
diinterpretasikan oleh web server, sehingga tidak
perlu khawatir apakah bahasa yang dipergunakan
mendukung browser yang dipergunakan pengunjung/
visitor.
Access to server-side resources. Resource terpenting
yang digunakan pada server-side adalah database, di
mana visitor dapat “insert content” dan “pulled out
content” dari sebuah basis data.
12
Server-Side Scripting
(Keuntungan 2)
13
Perl
15
Contoh Script Perl
my $x = "foo";
my $some_condition = 1;
if ($some_condition) {
my $y = "bar";
print $x; # prints "foo"
print $y; # prints "bar"
}
print $x; # prints "foo"
print $y; # prints nothing; $y has fallen out of
scope
16
ASP
17
Contoh Script ASP
18
Sejarah PHP
PROFILE
Rasmus Lerdorf
November 22, 1968, in Qeqertarsuaq, Greenland.
A Danish programmer with Canadian citizenship.
Notable as the creator of the PHPprogramming
language.
Sejarah PHP
20
PHP
PHP 5 dirilis Juli 2004 menggunakan Zend Engine 2.0 yang
mendukung model objek dan fitur terbaru.
Saat ini versi yang banyak dipakai adalah PHP 5.2.x
PHP 6 dirilis di tahun 2009 yang mendukung namespace dan
tambahan fitur baru lainnya
PHP 7 tahun 2019, versi terbaru dari bahasa pemrograman
ini membuat website Anda lebih cepat, aman, dan powerful
PHP 8 dirilis tahun 2020, Keunggulan pertama PHP 8 adalah
memiliki sistem Null Safe Operator yang berguna untuk
meringkas kode pemrograman untuk mengecekan hasil
coding guna menghindari null. Dulu, untuk mengecek hasil
coding dan mengetahui adanya error null atau tidak, kita
akan menuliskan validasi null dengan kode is_null. Di PHP 8,
penulisan untuk error checking menjadi lebih simpel. 21
Keunggulan PHP versi 8
Versi sebelum PHP 8:
<?php
if ($siswa) {
$alamat = $siswa->getAlamat();
if ($alamat) {
$namajalan = $alamat->getNamaJalan ();
}
}
Versi PHP 8:
$namajalan = $siswa?->getAlamat()?-
>getNamaJalan (); 22
PHP
# For PHP 4
Action application/x-httpd-php
"/php/php.exe"
# For PHP 5
Action application/x-httpd-php "/php/php-
cgi.exe"
Notes:
CGI (Common Gateway Interface) is an internet programming languagemost commonly used for handling form processing (ie information
request form). CGI can also be used for searching and database control.
Konfigurasi sebagai Server
module
# For PHP 4 do something like this:
LoadModule php4_module "c:/php/php4apache2.dll"
# Don't forget to copy the php4apache2.dll file
from the sapi directory!
AddType application/x-httpd-php .php
<?php
phpinfo();
?>
php –i
php namafile.php
29
PHP dan HTML
<html>
<head>
<title>Example</title>
</head>
<body>
<?php echo "Hi, I'm a PHP script!"; ?
>
</body>
</html>
30
PHP dan HTML
<html>
<head>
<title>Example</title>
</head>
<body>
Hi, I'm a PHP script!";
</body>
</html>
31
PHP dan Perl
print “<html>\n”
print “<head>\n”
print “<title>Example</title>\n”
print “</head>\n”
print “<body>\n”
print “Hi, I'm a PHP script!\n"
print “</body>\n”
print “</html>\n”
32
PHP dan C
33
Rangkuman