الأسبوع 2 · الوحدة ١ «أساسيات تصميم موقع الويب» (٢): HTML وPHP وبرنامج خادم الويب، نشر الموقع (محليًا أو باستضافة)، لغة SQL ونظام قاعدة البيانات، حزم تطبيقات الويب، الجلسة · 3 دروس
3
Ready-made kits, SQL and the session
ICT Secondary 2 Term 1, Unit 1, Topic 1: pp. 14–19
GoalSay what a web-server package, SQL and a session are for.
New words
web-server package · a ready-made bundle of a web server program, a database system and PHPSQL · the language used to talk to a relational databaseMySQL · a relational database management system (RDBMS): a program that stores tables and the relations between themsession · the way a server remembers a visitor from page to page
Explanation
Installing a web server, a database system and PHP one by one is slow, so free packages bundle all three. There is one for each operating system, and they differ in nothing important except the system they run on. SQL is the language you use to talk to a database. It has four main jobs: INSERT adds a record, SELECT shows records, UPDATE changes them and DELETE removes them. MySQL is one relational database management system: a program that keeps tables and the links between them. The session solves a problem: the web forgets the visitor after every page. With a session the server keeps a small note about the visitor, and the browser sends back a short id with each request, so the server knows who is asking. The site then allows or refuses a page by a condition. Never keep the password in the session: keep only a fact such as “member 12 is signed in”. Sign-in itself comes later in the year.
member signs in→server keeps: member 12 is signed in→browser returns the id with each request→server checks the condition: allow or refuse
Worked examples
Kit
Runs on
Web server
MySQL
PHP
Kit A
system 1
yes
yes
yes
Kit B
system 2
yes
yes
yes
Kit C
system 3
yes
yes
yes
Three invented kits: Kit A runs on system 1, Kit B on system 2, Kit C on system 3. Each one contains the same three parts. Only the system differs.
Question on the page
Answer
Result
a member is signed in?
yes
show the form
a member is signed in?
no
show a message
Karim signs in. The server notes “member 12 is signed in” in his session. On the next page, add_term.php, the server asks: is a member signed in? If yes, it shows the form. If no, it shows a message. The password is not stored in the session.
Class activity
On paper, write the four SQL jobs in a table. Next to each, write one thing the club might want to do (for example: add a new book, show all books by one writer, change a book’s shelf, remove a lost book).
Practice
1
What three parts does a web-server package bundle?
A web server program, a database system and PHP.
2
Which SQL job shows records, and which one removes them?
SELECT shows records; DELETE removes them.
3
Why does a site need a session?
The web forgets a visitor after each page; the session lets the server remember who he is from page to page.
4
What should a session never hold, and what may it hold instead?
Never the password. It may hold a fact such as “member 12 is signed in”.