الأسبوع 11 · الوحدة ٣ «إنشاء صفحات الموقع» (٤) الموضوع الأول (نهاية): صفحة الاتصال بقاعدة البيانات: ما يحتاجه الاتصال، قراءة صفحة الاتصال، حفظ الأسرار · 3 دروس
3
Shared pages and keeping secrets
ICT Secondary 2 Term 1, Unit 3, Topic 1: pp. 82–85
GoalInclude the connection page, and keep a database’s secrets safe.
New words
include · pulls another file into this page at that placecharacter set · the table of letters the connection uses, so that Arabic and English show correctlylimited rights · a database user who may do only the jobs the site needssecret · information such as a password that must not appear in a page or be shared
Explanation
Each page of the site starts by including the connection page: <?php include("connection.php"); ?>. PHP pulls the file in at that place and runs it, so the connection is open for the rest of the page. If you move the database or change the password, you change one file. Secrets need care. The book uses the user root with an empty password. That is only for a test on your own computer. A real site uses a database user with limited rights, only the jobs it needs, so if the password leaks the damage is small. It uses a long secret password, and it keeps the connection file outside the folders visitors can read. In lessons, every password is an invented placeholder. One more fact: the connection also has a character set, usually utf8mb4, which lets Arabic terms be stored and shown correctly. You will meet it again in Week 14.
page starts→include connection.php→connected: the page goes on→not connected: a short friendly message
Worked examples
Test on own computer
Real site
User
root, all rights
a user with limited rights
Password
empty
long and secret
Where the file is
in the project folder
outside the folders visitors can read
Printed on a page?
never
never
Hana compares two ways of keeping connection details. The left column is fine on her own computer while she tests, the right column is the way for a real site.
A page that includes the connection. The include line pulls connection.php in; the next line runs only after the connection is ready. If connection.php prints nothing when it works, the visitor sees only what the page itself prints.
Class activity
Write a short checklist on paper called “Keeping the connection safe” with five points (for example about the user, the password, where the file is, error messages and test values). Add one example of a bad habit for each point.
Practice
1
What does include do?
It pulls another file into the page at that place and runs it.
2
Why is root with an empty password only for a test on your own computer?
It has all rights and no protection; on a real site that would be dangerous.
3
What is a database user with limited rights?
A user who may do only the jobs the site needs, so a leak causes less damage.
4
Why does the connection have a character set?
So that Arabic and English terms are stored and shown correctly.