الأسبوع 1 · الوحدة ١ «أساسيات تصميم موقع الويب» (١): هدف الوحدة، البرامج المجانية ومفتوحة المصدر، صفحات الويب الساكنة والديناميكية، الخوادم والسكريبتات · 3 دروس
3
Servers and scripts: who does the work
ICT Secondary 2 Term 1, Unit 1: pp. 7–13
GoalDescribe a server as a role, and tell server-side code from client-side code.
New words
web server · a role: storing site pages and sending them to browsers that askclient · the device or program that asks a server for somethingserver-side language · a language whose code runs on the server, such as PHPclient-side language · a language whose code runs in the browser, such as JavaScript
Explanation
“Server” can mean a machine, but it is better to think of it as a role: a computer that answers requests from clients. A web server stores site pages and sends them to browsers; a print server takes print jobs from many computers; a mail server stores messages; a database server keeps tables of records. One machine may play several roles at once, and a big site may use several machines. A script is a short list of instructions written for web pages. Server-side code, such as PHP, runs on the server: the browser receives only the finished HTML and never sees the PHP. Client-side code, such as JavaScript, is sent to the browser and runs there. It is quick, for example to warn “the name box is empty” without waiting for the server. But a browser can be bypassed, so the server must check again; whether a member number really exists in the database can only be checked on the server.
Worked examples
browser (client)→web server: sends the page→database server: gives the records
One small computer in the club room is a web server and also a print server. It is one machine with two roles. A big site might put the web server and the database server on two different machines.
Check
Where it can run
name box not empty
browser (quick) and server (safe)
member number exists
server only
A sign-up form has two checks. “The name box must not be empty” can run in the browser as client-side code, which is fast. “Is member number 12 in the database?” can only be answered on the server. The server also repeats the empty-name check, because a browser can be bypassed.
Class activity
Make a table of four servers you could find in a school (web, print, mail, database). For each write what it keeps or does, and what a client would ask it for. Then say which one a visitor to the club’s website talks to first.
Practice
1
Who runs PHP code: the browser or the server?
The server. The browser only receives the finished HTML.
2
Can one computer be both a web server and a mail server? Explain.
Yes. “Server” is a role, and one machine can play several roles.
3
Why is a quick check in the browser not enough on its own?
A browser can be bypassed, so the server must check again.
4
Is JavaScript a server-side or a client-side language?