AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Communication Technology

The connection page

Week 11 · Unit 3 Creating Site Pages (4), Topic 1 (end): the page that connects to the database: what a connection needs, reading a connection page, keeping secrets · 3 lessons
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.

Worked examples
Test on own computerReal site
Userroot, all rightsa user with limited rights
Passwordemptylong and secret
Where the file isin the project folderoutside the folders visitors can read
Printed on a page?nevernever
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.
Php
1<?php
2include("connection.php");
3echo "Page ready";
4?>
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?
2
Why is root with an empty password only for a test on your own computer?
3
What is a database user with limited rights?
4
Why does the connection have a character set?