<<

Programmare server

Programmazione Web 1 RequestRequest to to a aDynamic Dynamic Site Site

! The! The server server must must respond respond dynamically dynamically if it if needs it needs to provideto provide differentdifferent client-side client-side code code depending depending on onthe the situation situation ! Date! Date and and time time Richiesta a un sito staco ! Specifics! Specifics of theof theuser’s user’s request request ! Database! Database contents contents – forms – forms and and authentication authentication

HTTP req: GET www.uniroma2.it Server: HTTPHTTP Request: Request: GET GETwww.facebook.com www.facebook.com Server: 1. Look1. Look up things up things that thatgo ongo on user’suser’s profile, profile, such such as as wall wallposts posts and andfriends friends " " caches,caches, database database lookups You (client)You (client) Webweb Web server server lookups client server 2. Generate2. Generate client-side client-side code containing these HTTPHTTP Response:HTTP Response:resp web: HTML, CSS, webcontent content (HTMLjs , ... (HTML file) file) code containing these things Client-sideClient-side code: code: HTML, HTML, CSS, CSS, JavaScript JavaScript things 3. Send3. Send as HTTP as HTTP response response (dynamically (dynamically generated generated by server) by server) Server 1. Riceve una richiesta per un file 2. Cerca il file e se lo trova lo invia in risposta

Programmazione Web 2 Richiesta a un sito dinamico RequestRequest to to a aDynamic Dynamic Site Site • Il server deve rispondere dinamicamente se è necessario fornire risulta diversi a seconda della ! The! The server server must must respond respond dynamically dynamically if it if needs it needs to provideto provide differentsituazione different client-side client-side code code depending depending on onthe the situation situation – Ora o data ! Date! Date and and time time – richieste specifiche ! Specifics of the user’s request – !Contenuto del DB – Specifics of the user’sform o autencazione request ! Database! Database contents contents – forms – forms and and authentication authentication

HTTP req: GET www.uniroma2.it Server Server: HTTPHTTP Request: Request: GET GETwww.facebook.com www.facebook.com 1.Riceve la richiesta e vede Server: 1. Look1. Look up things up things that thatgo ongo on che è per una risorsa user’suser’s profile, profile, such such as as "dinamica" wall wallposts posts and andfriends friends " " 2. esegue il codice associato caches,caches, database database alla risorsa lookups You (client)You (client) Webweb Web server server lookups client server 3. invia l'output del codice al 2. Generate2. Generate client-side client-side code containing these HTTPHTTP Response:HTTP Response:resp web: HTML, CSS, webcontent content (HTMLjs , ... (HTML file) file) client code containing these things Client-sideClient-side code: code: HTML, HTML, CSS, CSS, JavaScript JavaScript things Programmazione Web 3. Send3. Send as HTTP as HTTP response response3 (dynamically (dynamically generated generated by server) by server)

Linguaggi per server • Php – linguaggio specifico per il web, open source, interpretato • CGI/ – Più vecchio del ma difficile da usare. Usato per creare degli script nei sistemi unix • ASP.NET – Linguaggio Microso, licenza commerciale; di pendente dalla piaaforma. • Coldfusion – linguaggio Adobe per chi non sa programmare, facile. costoso il server. • Python – Linguaggio ad ogge per scripng generici. • (JSP o servlet)- Java server-side programming, richiede Apache Tomcat o simili. • Ruby – linguaggio generico a ogge • Javascript – server di script come node.js

Programmazione Web 4 Caraerische da confrontare • Embedding – L'HTML è inserito nel codice (con delle print) o è il codice inserito nell'HTML? • Flexibility – quante strade ho per la soluzione del mio problema? • Usability – quanto è difficile da imparare e da usare il linguaggio? • Security – sviluppare nel linguaggio scelto è sicuro o devo scrivere del codice per garanre la sicirezza? – Ci sono buchi di sicurezza nel linguaggio? • Speed of execuon – Con che velocità viene eseguito uno script? • Generality – Il linguaggio è generico o specifico?

Programmazione Web 5 Stasche

Programmazione Web 6 Classifica per i maggiori si

Programmazione Web 7 Programmazione Web 8 Programmazione Web 9 Popular sites using PHP • Facebook.com • Baidu.com • Wikipedia.org • Qq.com • Twier.com • Taobao.com • Sina.com.cn • Vk.com • Pinterest.com • Onclickads.net

Programmazione Web 10 Content Management Systems • Applicazione lato server – memorizza i contenu su dB – una sezione di amministrazione (back end), per gesre i contenu; – una sezione applicava (front end),per mostrare i contenu

• CMS famosi – wordpress – joomla – drupal – magento – django

Programmazione Web 11 Content Management Systems

Programmazione Web 12 Content Management Systems

Programmazione Web 13 PHP

Programmazione Web 14 Cosa è PHP?

• PHP è l’acronimo ricorsivo di “PHP HyperText Preprocessor” – Inizialmente era l’acronimo di “Personal Home Page” • PHP è un linguaggio di programmazione creato da Rasmus Lerdorf nel 1994 per costruire delle estensioni in documen HTML e migliorare così la sua home page personale – Porzioni del documento HTML sono generate dinamicamente • PHP è open source

Programmazione Web 15 Cosa è PHP

• PHP convive normalmente all’interno di documen HTML – È possibile creare degli script in PHP esegui da una shell • PHP viene normalmente eseguito dal server prima che la pagina venga inviata all’utente • L’output di PHP è normalmente codice HTML per il browser, ma ci sono molte eccezioni – Può generare anche immagini, documen pdf, documen XML, filma Flash, ...

Programmazione Web 16 Storia • 1994 – PHP fu pensato e sviluppato nell’autunno del 1994 da Rasmus Lerdorf (membro del team di sviluppo di Apache). • 1995 – Rilasciato PHP/FI (Form Interpreter) versione 2. Permeeva l’accesso a database (MySql) • 1997 – Rilasciato PHP versione 3 (riscriura in ++ dell’interprete da parte di Zeev Suraski e Andi Gutmans) • 2000 – Rilascio di PHP 4 basato sul motore di scripng Zend www.zend.com • 2004 – Rilascio di PHP 5

Programmazione Web 17 Vantaggi

• La curva di apprendimento è brevissima • Veloci tempi di sviluppo • Alte prestazioni e stabilità • Supporto dei sistemi opera principali (UNIX, , Windows, ...) • Supporto navo per i database più popolari • Molte librerie built-in • Pre-installato nelle distribuzioni Linux

Programmazione Web 18 Esempio PHP – hello.php

Programmazione Web 19 Risposta server

Programmazione Web 20 RequestRequest to to a aDynamic Dynamic Site Site

! The! The server server must must respond respond dynamically dynamically if it if needs it needs to provideto provide differentdifferent client-side client-side code code depending depending on onthe the situation situation ! Date! Date and and time time Architeura web con ! Specifics! Specifics of theof theuser’s user’s request request php ! Database! Database contents contents – forms – forms and and authentication authentication

HTTP req: GET www.uniroma2.it/hello.php Server: HTTPHTTP Request: Request: GET GETwww.facebook.com www.facebook.com Server: 1. Look1. Look up things up things that thatgo ongo on user’suser’s profile, profile, such such as as wall wallpostsphp posts and andfriends friends " " caches,caches, database database lookups You (client)You (client) Webweb Web server server lookups client 2. Generate2. Generate client-side client-side server code containing these HTTPHTTPHTTP Response: Response:resp: output dell' interprete web webcontent content (HTML (HTML file) file) code containing these Client-side code: HTML, CSS, JavaScript thingsthings Client-side code: HTML, CSS, JavaScript 3. Send as HTTP response (dynamically generated by server) 3. Send as HTTP response (dynamically generated by server) 1. richiesta di un documento con estensione .php 2. il server invia il documento al PHP 3. PHP interpreta lo script produce un output 4. il server produce la risposta HTTP

Programmazione Web 21 Esempio PHP – hello2.php

Programmazione Web 22 Esempio PHP 2 – hello3.php

Programmazione Web 23 Esempio PHP - CSS

Programmazione Web 24 Inserire codice php

• Tuo quello che è racchiuso fra i tag viene interpretato dal modulo PHP – in alcuni casi si può omeere il tag di chiusura • Metodi alternavi per inserire codice php – da configurare in php.ini – (short_open_tag) – NON PIU' SUPPORTATO – <% CODICE PHP %> (asp_tags) –

Programmazione Web 25 Pagina di configurazione

• Per vedere quali parcolari estensioni sono state installate o per vedere come il file php.ini è stato configurato è possibile eseguire il seguente script ! • Inserire la riga precedente in un file (e.g., info.php) e poi invocare hp://localhost/info.php • La funzione phpinfo() crea una pagina HTML contente informazioni su come PHP è stato installato

Programmazione Web 26 Errori in PHP

• Il server non comunica gli errori al client • Possiamo modificare una direva in php.ini per mostrare nel browser gli eventuali errori (solo il primo) di script PHP • Cercare la direva display_errors e seare – display_errors = On • SOLO PER DEBUGGING

Programmazione Web 27 Ambiente server

• Server STUD – Apache con modulo php – Mysql

• Soware per lavoro in locale – Xampp – WINDOWS, LINUX, MAC – Easyphp – WINDOWS – Wamp – WINDOWS

Programmazione Web 28 Sviluppare con IDE

• NetBeans + Chorme Connector – hp://www..org

PDT – hp://eclipse.org/pdt/downloads/ • Komodo IDE – hp://acvestate.com/Products/komodo_ide • phpDesigner – hp://mpsoware.dk • PHPEclipse – hp://phpeclipse.de • PhpED – hp://nusphere.com • PHPEdit – hp://www.phpedit.com

Programmazione Web 29 Verificare il proprio ambiente

• Creare programma hello.php

• Creare programma info.php

Programmazione Web 30