Your SlideShare is downloading. ×
0
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Php kel23
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Php kel23

435

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

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

×