Server-side Scripting Slides courtesy of Xenia Mountrouidou URLs - - PowerPoint PPT Presentation

server side scripting
SMART_READER_LITE
LIVE PREVIEW

Server-side Scripting Slides courtesy of Xenia Mountrouidou URLs - - PowerPoint PPT Presentation

Server-side Scripting Slides courtesy of Xenia Mountrouidou URLs and web servers 2 http://server/path/file Usually when you type a URL in your browser: Your computer looks up the server's IP address using DNS Your browser connects


slide-1
SLIDE 1

Server-side Scripting

Slides courtesy of Xenia Mountrouidou

slide-2
SLIDE 2

URLs and web servers

 Usually when you type a URL in your browser:

 Your computer looks up the server's IP address using

DNS

 Your browser connects to that IP address and requests

the given file

 The web server software (e.g. Apache) grabs that file

from the server's local file system

 The server sends back its contents to you

2

http://server/path/file

slide-3
SLIDE 3

URLs and web servers (cont.)

3

Web/Application Server

Apache, Websphere (Java Servlets, XML Files)

Database

slide-4
SLIDE 4

URLs and web servers (cont.)

 Some URLs actually specify programs that the web

server should run, and then send their output back to you as the result:

 The above URL tells the server facebook.com to run the

program home.php and send back its output

4

http://www.facebook.com/home.php

slide-5
SLIDE 5

What are they and what are their differences?

Server-Side vs. Client-Side Scripting Languages

By Lories Slockbower

slide-6
SLIDE 6

Scripting Language

 A new style of programming language different from

system programming languages

 Designed as glue language or system integration

language

 A single statement can execute huge number of

machine instructions

 Are normally ‘typeless’  Build complex algorithms and data structures..  Can create dynamic web pages

 Change based on user input

slide-7
SLIDE 7

Types of Scripting Languages

 Server-side Scripting Language  Can use huge resources of the server  Complete all processing in the server and send plain pages to the client  Reduces client-side computation overhead  Client-side Scripting Language  Does not involve server processing  Complete application is downloaded to the client browser  Client browser executes it locally  Are normally used to add functionality to web pages e.g. different menu

styles, graphic displays or dynamic advertisements

slide-8
SLIDE 8

Different Scripting Languages

 Active Server Pages (ASP)  Server side scripting language  Developed by Microsoft  Good at connecting to Microsoft databases  Runs only on Microsoft servers  Perl  Old UNIX language  Found on all Windows and Linux servers  Can handle text manipulation tasks  Excellent web scripting language

slide-9
SLIDE 9

Different Scripting Languages

 PHP (Hypertext Pre-Processor)  Especially good at connecting to MySQL  Very popular language  Runs on UNIX and Windows  HTML-embedded scripting language  Syntax looks like C, JAVA, and PERL  Generate Dynamic content and good User Interface  Server side execution  JSP (Java Server Pages)  Developed by Sun  Uses Java  Provide server-specific framework like Microsoft’s ASP

slide-10
SLIDE 10

Different Scripting Languages

 CGI (Common Gateway Interface)  Server-side solution  Needs to launch separate instance of application for each web request  Allows direct interaction with users  ASP.NET  Server-side technology to create faster, reliable and dynamic web

pages

 Supports .NET framework languages (C#, VB.NET, JScript.NET)  Provides flexibility to designers and developers to work separately

slide-11
SLIDE 11

Different Scripting Languages

 VBScript  Microsoft’s scripting language  Client side Scripting language  Very easy to learn  Includes the functionality of Visual Basic  JavaScript  Client-side Scripting language  Easy to use programming language  Enhance dynamics and interactive features of a web page  Allows to perform calculation, write interactive games, add special

effects, customize graphic selections, create security passwords

slide-12
SLIDE 12

Conclusion

 Scripting languages make the web development work  Easier  Faster  Best utilization of resources  It is the programmer’s choice which one will suite the

best considering

 Knowledge  Practice  Resource

slide-13
SLIDE 13

What is server-side scripting?

 Server-side scripting is a

method of programming for the web that runs software on the server rather than the browser

  • r installed plugins to

create dynamic web pages.

slide-14
SLIDE 14

Server-Side Scripting

 Server-side pages are programs written using one

  • f many web programming languages/frameworks

 examples: PHP

, Java/JSP , Ruby on Rails, ASP.NET, Python, Perl

14

slide-15
SLIDE 15

What can server scripts do?

 Customize a web page

and dynamically change its contents

 Respond to queries

from users or from HTML forms

 Access database and

send the information back to the browser

slide-16
SLIDE 16

Advantages of server-side scripting

 User does not need to download

plugins like Java or Flash

 User can create one template for

the entire website

 The site can use a content

management system which makes editing simpler.

 Generally quicker to load than

client-side scripting

 User is able to include external files

to save coding

 Scripts are hidden from view so it’s

more secure. Users only see the HTML output.

slide-17
SLIDE 17

Disadvantages of server-side scripting

 The scripts can be used by

attackers to access the server. They do this by changing the URL to something that takes advantage of a hole in

  • security. System administrators

must keep all server-side scripting updated and use an application firewall to prevent this.

 Scripting software must be

installed on the content management system tools in

  • rder to store the dynamic

data.

slide-18
SLIDE 18

Server-side scripting example

ASP source:

<html> <body> <% response.write("Hello World!")%> </body> </html>

Output result

 Hello world!

slide-19
SLIDE 19

What is client-side scripting language?

Client-side scripts are placed within an HTML document in the user’s web browser rather than the web server to allow greater interactivity in a

  • document. For example – client-side

scripting could check the user’ s form for errors before submitting it

Enables web pages to change content according to user input and

  • ther variables, including the time of
  • day. Can also be stored in a

separate file that is referenced to the documents that use it.

slide-20
SLIDE 20

How does it work?

 Usually, JavaScript code

starts with the tag <script language="JavaScript"> and ends with the tag </script>.

 Files are first sent to the

user’s computer by the web server which executes the script and displays the document.

 The client-side script may

also include browser directions based on certain user functions such as clicking buttons.

 Frequently, you can see

the the source card by viewing the file that contains the script.

slide-21
SLIDE 21

Example of client-side scripting

 Suppose a person

completes a form but

  • mits information. When

they slick the submit button, an alert box appears telling them about the mistake.

 This is JavaScript and is

an example of Client Side Scripting because all the activity takes place inside the browser.

slide-22
SLIDE 22

Advantages of client-side scripting

 Allows for more interactivity  Can perform actions quickly

without going to the server

 May be easier to use for

those whose browsers don’t support scripts

 Are available from many free

resources such as Hotscripts.com and Javascript.com

slide-23
SLIDE 23

Disadvantages of client-side scripts

 If the user’s browser is out of date, the website will

not display properly.

 More quality assurance testing is required because

different browsers support scripts differently

 Not secure because anyone can look at the code in

the page source

 Some browsers will disable the active content and

tell the user they may be harmful.

slide-24
SLIDE 24

Client-side scripting language

 JavaScript – Not to be

confused with Java, JavaScript client-side is a programming language is implemented as part of the web browser to enhance dynamic websites

 VBScript is a programming

language that can manipulate the document objects and the browser

slide-25
SLIDE 25

So how to know which to use?

 Know your audience – Be sure to

know what scripts work best with the browsers your audience will

  • use. JavaScript is most compatible

with Microsoft Internet Explorer and Netscape. VBScript usually just works on Internet Explorer.

 Test scripts on the browsers for

both PC and MAC users as browsers on the MACs don’t support scripts as well as the PC versions do.

 Scripts should be tested on at

least the previous two versions

  • f your audience’s browser since

people are slow to update their browsers so the latest scripts may not work.

slide-26
SLIDE 26

Client Side vs. Server Side Web

 Simply defined, client-side code executes on the end-user's

computer, usually within a web browser.

 Server-side code executes on the web server, usually within a

web application environment, which in turn generates HTML to be viewed in a browser.

slide-27
SLIDE 27

Client Side vs. Server Side Web

 Which one to choose? What are the determining factors?  Performance:

 Responsiveness, speed, reliability  Ability to handle a large number of simultaneous users  Functionality:  Simplicity of use and maintenance,  Breadth of user options  Ability to handle multiple simultaneous transactions  Security:  Desktop security  Server security  Database security  Network security

slide-28
SLIDE 28

Client Side vs. Server Side Web

 Examples:

 Code that runs on the server that interprets every

mouse move and keystroke is clearly undesirable

 terminal to mainframe paradigm

 On the other hand, one does not want to download an

entire product database to a browser and then run code that searches for the products.

 Server side forms have direct access to active code and

perform more reliably

 On the other hand they are more prone to slowdowns

due to the server/network congestion

slide-29
SLIDE 29

Client Side vs. Server Side Web

 In general, the key areas where client-side coding has advantages stem

from its location on the user desktop and/or other end device. They include the following:

 Interactivity (e.g., mouse and keyboard handling)  Handling of user interface controls: buttons, textboxes, etc.  Feedback and validation

 Key server-side strengths include stem from their proximity to the backend

business databases and other applications. They include the following:

 Direct information access, retrieval, processing and storage

 facilitate e-commerce, reservations, shipment tracking etc.

 central repository of added web features such as e-mail, chat and multimedia

streaming

 security and authentication (mostly)

slide-30
SLIDE 30

PHP

EPL344

30

slide-31
SLIDE 31

What is PHP?

 PHP stands for "PHP Hypertext Preprocessor"  Server-side scripting language  Used to make web pages dynamic:

 provide different content depending on context  interface with other services: database, e-mail, etc.  authenticate users  process form information

 PHP code can be embedded

in XHTML code

31

slide-32
SLIDE 32

Lifecycle of a PHP web request

32

Hello world!

User’s computer Server computer Hello.php

slide-33
SLIDE 33

Why PHP?

 Free and open source  Compatible  Simple

33

slide-34
SLIDE 34

Hello World!

34

<?php print "Hello, world!"; ?> PHP

Hello world!

  • utput
slide-35
SLIDE 35

Viewing PHP output

35

Hello world!

slide-36
SLIDE 36

PHP syntax template

36

 Contents of a .php file between <?php and ?> are executed

as PHP code

 All other contents are output as pure HTML  We can switch back and forth between HTML and PHP

"modes"

HTML content <?php PHP code ?> HTML content <?php PHP code ?> HTML content ...

PHP C:\Users\SCRAT\Dropbox\Belk\UCY Teaching\EPL344