• Like
  • Save
Php kel23
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
420
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. OLEH :
    Kukuh Hannugroho 5108100054
    Romario Sumali 5108100096
    Miko Hendro C 5108100162
    PHP
  • 2. Introduction
    PHP
    String and Regular Expressions
    Viewing Client/Server Environment Variables
    Form Processing and Business Logic
    Verifying a Username and Password
    Connecting to a Database
    Cookies
    Operator Precedence
  • 3. Open source
    Processed by the web server and plain HTML is returned to the browser.
    Database support includes: MySQL, mSQL, Informix, Oracle, Sybase, Solid, PostgreSQL, ODBC, and more.
    Some advanced features: Authentication, XML, dynamic image creation, WDDX, shared memory support, and dynamic PDF document creation
    Introduction
  • 4. PHP was created in 1994 by RasmusLerdorf
    1995, Lerdorf merilis “PersonalHome Page Tools.” PHP 2 mampu menangani database dan form handling.
    1998, PHP 3 support multiple platforms dan web servers, database yang besar, serta SNMP (Simple Network Management Protocol) dan IMAP (Internet Message Access Protocol).
    PHP 4 dengan fitur Zend Engine dan lebih cepat dan powerful dari sebelumnya
    PHP 5 lebih cepat lagi, mendukung baik procedural maupun object oriented script
    Introduction – Brief History
  • 5. PHP(1994) was created by RasmusLerdorf . It was initially developed for HTTP usage logging and server-side form generation in Unix.
    PHP 2 (1995) transformed the language into a Server-side embedded scripting language. Added database support, file uploads, variables, arrays, recursive functions, conditionals, iteration, regular expressions.
    PHP 3 (1998) added support for ODBC data sources, multiple platform support, email protocols (SNMP,IMAP), and new parser written by ZeevSuraski and AndiGutmans.
    Introduction – Brief History
  • 6. PHP 4 (2000) became an independent component of the web server for added efficiency. The parser was renamed the Zend Engine. Many security features were added.
    PHP 5 (2004) adds Zend Engine II with object oriented programming, robust XML support using the libxml2 library, SOAP extension for interoperability with Web Services, SQLite has been bundled with PHP
    Introduction – Brief History
  • 7. Easy to Use
    Cross Platform
    Cost Benefits
    Speed and robustness.
    Superior Memory Management
    No Hidden Costs with PHP
    Integration with MySQL database.
    Closer to Java/C++ Style of Programming.
    Introduction – Reason using PHP
  • 8. PHP code is embedded directly into XHTML documents.
    This allows the documentauthor to write XHTML in a clear, concise manner, without having to use multiple printstatements, as is necessary with other CGI-based languages
    Penulisan code PHP diletakkan diantara delimiter <?phpdan?>.
    Statements ditutup dengan semicolon (;).
    PHP - Basic
  • 9. Dimulai dengan $
    Dapat terdiri dari huruf, angka, dan underscore (tidak boleh angka setelah $)
    Tidak memerlukan deklarasi variabel
    Variables tidak memiliki intrinsic type selain type dari current value.
    Predifine variabel :
    $GLOBALS, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILE, $_REQUEST, $_SESSION
    PHP - Variabel
  • 10. PHP – simple example
  • 11. PHP – data type and keyword
  • 12. PHP – conversion data type
    Menggunakan fungsi settypeatau dengan casting
    Fungsi settype dapat menyebabkan berkurangnya data.
    Double  integer, angka setelah koma hilang
    String  a number, yang diambil hanyalah angka di depan string
    Casting tidak mengubah isi variabel. Type casting akan membuat temporary copy dari data.
    Concatenation operator (.) digunakan untuk menggabungkan string dalam print statement yg sama
  • 13. PHP – data type example
  • 14. PHP – control structure
  • PHP – control structure
    If:
    $hey = TRUE;
    If($hey) {
    printf(“Hello ”);
    } else {
    printf(“Never gona see this! ”);
    }
    While
    $a = 0;
    while($a < 100) {
    printf(“hello $a ”);
    $a++;
    }
    For
    for($a = 0; $a < 100; $a++){
    printf(“Hello $a ”);
    }
  • 30. PHP – arithmetic operators
  • 31. PHP – arithmetic operators
  • 32. String and Regular Expressions
    strcmp: membandingkandua string
    -1 : string pertamalebihkecildari string kedua
    0 : kedua string sama
    1 : string pertamalebihbesardari string kedua
    Operator relasionaljugabisauntukmembandingkandua string
    ==, !=, <, <=, >, >=
  • 33. String and Regular Expressions – string comparison example
  • 34. String and Regular Expressions
    ereg(a,b)
     mencarisekumpulankaraktera didalam string b
    Eregi
     sama dengan ereg namun case insensitive
    Karenaereghanyamenyimpansatukata yang cocok, untukbisamendapatkanlebihdarisatukatadiperlukanereg_replaceuntukmenghapuskata yang sudahcocok
  • 35. String and Regular Expressions
    Selainkarakter literal, adajugakarakterspesial
    ^: diawal string
    $:diakhir string
    .: suatukaraktertunggal
    []: sekumpulankarakter
    -: range karakter
    [[:<:]]dan[[:>:]] : awaldanakhirsuatukata
    Quantifiers
    {n}Tepatn kali
    {m,n}Antaramdann kali (inklusif)
    {n,}nataulebih
    +satuataulebih (samadengan{1,})
    *nolataulebih (samadengan{0,})
    ?nolatausatu kali (samadengan{0,1})
  • 36. String and Regular Expressions – regular expression example
  • 37. Mengetahui client’s execution environment berguna bagi system administrator dalam menyediakan informasi client secara spesifik.
    Environment variables mengandung informasi mengenai script’s environment, seperti client’s Web browser, HTTP host dan koneksi HTTP.
    Viewing Client/Server Environment Variables
  • 38. Viewing Client/Server Environment Variables
  • 39. Form digunakan untuk mengumpulkan data dari user kemudian mengirimkan ke web server
    Form sangat dibutuhkan pada aplikasi yang membutuhkan interaksi antara user dan web server, contohnya pada e-commerce
    Contoh form
    Form Processing and Business Logic
  • 40. Form
  • 41. Form
  • 42. Form
  • 43. Form
  • 44. Field user name dan password terdapat pada PHP script password.php
    Data tidak akan diencript sebelum dikirim ke server
    Verifying a Username and Password
  • 45. Verifying a Username and Password
  • 46. Verifying a Username and Password
  • 47. Verifying a Username and Password
  • 48. Verifying a Username and Password
  • 49. Adabanyakcarauntukkoneksike database dari PHP. Salah-satunya PHP mendukungkoneksilangsungke database MySQL melaluifungsi-fungsisepertimysql_connect(), mysql_query()dsb.
    Pertama kali pastikanmodulMDB2 telahdipanggildi script PHP.Hal inidapatdilakukandenganmeng-include-kankodeMDB2 kedalam script PHP menggunakan statement require_once.
    Connecting to a Database
  • 50. Connecting to a Database - Setup MDB2
    Hal inidapatdilakukandenganmeng-include-kankodeMDB2 kedalam script PHP menggunakan statement require_once.
    <?php
    require_once "/usr/local/lib/php/MDB2.php";
    ?>
    UntukmendapatkankoneksigunakanfungsiMDB2::connect() yang argumennyaberupasebuahdata source name.
    $dsn = "mysqli://pbwc:XXXXXX@localhost/pbwc";
    $conn =& MDB2::connect($dsn)
    Kodediatasmenghubungkan user pbwckedatabase pbwcpadamesinlokaldenganpassword XXXXXX – sintaksumumdaridata source nameadalah
    phptype://username:password@hostspec/database
    Padacontohinibagianmysqli artinyamenggunakan driver “MySQL Improved”.
  • 51. Pengecekan Koneksi
    FungsiMDB2::connect() bisagagalkarenabeberapaalasanseperti server yang tidakbisadihubungi, password yang salah, dsb. Olehkarenaitupengecekanterhadapvariabelkoneksisangatpentinguntukmemastikantidakada error.
    Jikaterjadi error fungsidiatasakanmengembalikansebuahobyek error yang berisiinformasitentang error yang terjadi.
    if (MDB2::isError($conn)) {
    print $conn->getUserInfo();
    print " ";
    die("Connection Failed ");
    }
    KodediatasmenggunakanfungsiMDB2::isError() untukmengecekapakah$conn adalahsebuaherror. Jikaya, makafungsinyadihentikandenganmenampilkaninformasitertentu.
  • 52. Cookies bergunauntukmengatasisifat ‘stateless’ dari web
    Cookies ditulisdi hard drive client.
    Permasalahan:
    User dapatmengeset cookies tidakdijalankandi browser
    Cookies dapatdilihatoleh user yang lain
    Hanyadapatmenyimpan 20 cookies; max 4KB.
    Beberapa browser bisamenampilkandenganbenarhanyajikaseluruh options disetdiperintahsetcookie()
    Cookies
  • 53. Pembuatan & Pengaksesan Cookies
    setcookie(name,value,expiration);
    Misal, setcookie(“fruit”,”banana”,time()+3600); Cookie dengannama ‘fruit’ dengannilai ‘banana’; akandihapus 1 jam darisekarang.
    Nilai cookie dikirimsebagaibagiandari header HTTP.
    Pengaksesan cookies :
    $_COOKIE berisinilaisetiap cookie yang sedangaktif
    <?
    foreach ($_COOKIE as $name =>$value)
    echo “<BR>$name => $value”;
    ?>
  • 54. Secaraotomatisterhapussetelahwaktu yang telahditentukansebelumnya (expiration time)
    Atausecara manual dihapusdenganmengeset cookie tertentudenganisivariabelwaktunegatif
    Menghapus Cookies
    setcookie(“username”,””,time()-3600);
  • 55. Operator precedence dariphpadalah :
    Operator Precedence