Lecture 14 - FSU Computer Science

Download Report

Transcript Lecture 14 - FSU Computer Science

CGS 3066: Web Programming and Design
Spring 2016
Introduction to Server-Side Programming
Static Web Page
• Up until now, all our efforts have been put to design “static” pages only:
1. Client requests URL: http://ww2.cs.fsu.edu/~mollah/path/to/webpage.html
2. Browser finds the IP address of http://ww2.cs.fsu.edu server: 128.186.122.20
3. Browser sends HTTP request to 128.186.122.20
GET /~mollah/path/to/webpage.html
4. The server finds the “document root” of its user “mollah”:
/home/grads/mollah
5. Appends the remaining URL with document root to obtain filename
/home/grads/mollah/path/to/webpage.html
6. Returns file content(HTML,CSS,Javascript) as HTTP Response to client
-exactly as the programmer wrote
Dynamic Web Pages
• Server responds “dynamically“
• Returns different client-side code depending on the situation
• Example: GET www.facebook.com/
•
•
•
•
Server determines the user through authentication (facebook login ID and password)
Looks up user-specific information(e.g. wall posts, inbox, chat history) from database
Generates Client side code(HTML+CSS+Javascript) to containing these content
Returns dynamically generated contents as HTTP response
• Requires programming logic on the Server Side!
Server Side Technologies: HTTP Servers
• Software Responsible for handling HTTP requests, invoke server side programming
• Apache: the most popular web server software
• Free and Open-source
• Supports a wide variety of server-side technologies
• Internet Information Services(IIS):
• Popular web server created by Microsoft
• Created for use with windows NT/server
• Better suited for (and heavily dependent on) Windows technologies,
Server Side Technologies: Databases
• A number of Relational database management systems(RDBMS) are currently in use:
• Uses SQL (Structured Query language) to manage(insert/update/search) data
• Server-Client Architecture:
• Oracle: Proprietary, most widely used in medium and large businesses
• SQL Server : Proprietary RDBMS from Microsoft
• MySQL (open source) : most popular open-source database
• PostgreSQL(open source): powerful, SQL standard compliant RDBMS
• Serverless Architechture:
• SQLite: lightweight, embedded SQL database engine. Stores database in a file
Server Side Programming:CGI
• Stands for “Common Gateway Interface”
• Pass HTTP request and parameters to an executable (called “CGI scripts”)
• Executable returns dynamically generated web content
Pros:
• CGI scripts can be written in any language(Perl, C/C++,Python, Bash script)
• Cons:
• Slow, Resource Intensive
• scripts may contain exploitable bugs, remote user may end up executing
commands on the server
Server Side Programming: ASP.NET
• “Active Server Page”, part of .NET framework developed by Microsoft
• Supports visual editing (drag and drop web controls)
• .NET framework supports many programming languages such as Visual
basic, C++, C#,J#
• Used to run on Windows only, currently being extended into a crossplatform framework
Server Side Programming: PHP
• Acronym for “PHP: Hypertext Preprocessor”
• Open-source language for server-side scripting
• Easy, yet powerful tool for writing dynamic web pages quickly
• Relatively flat learning curve
• Free!
• Efficient alternative to competitors such as Microsoft's ASP.NET
• All major content management sytems currently in use (WordPress, Drupal,
Joomla) are written in PHP
• Also facebook.com, yahoo.com, Wikipedia.org, sourceforge.net!
PHP Sneak peek
• Pages with PHP scripts are saved with .php extension
• If an http request is for a file with .html extension, server simply returns that file
• However, If the request is for a .php file:
• Server reads the file to see if any script code (PHP) is embedded in it
• If there is PHP code, server executes the code and sends whatever is
generated
• PHP code snippets are interspersed within HTML content
• PHP code begins with <?php and ends with ?>
• Let’s try ”Hello world” with PHP!
Learning Server-Side programming
• Unlike HTML, CSS and Javascript, Server-side scripts cannot be tested on browser
• Must run on a server (therefore called “server-side”)
• ww2 server runs Apache HTTP server with PHP
• MySQL databases may only be created on the DB server(dbsrv.cs.fsu.edu). Contact systems
group(again!!) to get access to dbsrv.
• SQLite may be used on ww2 server space 
• Will be discussed in due time
Learning Server-Side programming
• Alternatively, you can set up your own HTTP server(Apache), database(MySQL/SQLite) and
scripting language(PHP) on your computer!
• Individual installing and configuration can be too tedious
• Solution: Use prepackaged software bundle:
• WampServer: http://www.wampserver.com/en/
• (A)pache, (M)ySQL, (P)HP bundle for (W)indows platform
• MAMP: https://www.mamp.info/en/downloads/
• My Apache - MySQL – PHP For OS X and Windows
• Ampps: http://www.ampps.com/downloads
• Cross platform(available for windows, MAC OS X and Linux)