Course / دورة
PHP: code that runs on a serverPHP: كود يعمل على خادم
The half of the web your browser never sees
نصف الويب الذي لا يراه متصفحك قط
intermediate 16 lessons 5 chapters 16 hours
Before you start / قبل أن تبدأ: Programming basics , How the web works
0 / 16 lessons completed / دروس مكتملة
What you will be able to do / ماذا ستستطيع أن تفعل
- Write PHP that turns a request into a page تكتب PHP يحوّل الطلب إلى صفحة
- Take what a visitor sends and handle it without trusting it تتعامل مع ما يرسله الزائر دون أن تثق به
- Keep someone signed in across pages, and know what that costs تُبقي أحدهم مسجَّلًا عبر الصفحات، وتعرف ما يكلّفه ذلك
- Read from and write to a database safely تقرأ من قاعدة بيانات وتكتب فيها بأمان
1 Code on a serverكود على خادم 3
-
1
The half you have never seen / النصف الذي لم تره قط
Everything you have built so far runs on the visitor's machine, where they can read it, change it and lie about it. Server code runs somewhere they cannot reach — and that difference is the entire reason the backend exists.
كل ما بنيته حتى الآن يعمل على جهاز الزائر، حيث يستطيع قراءته وتغييره والكذب بشأنه. أما كود الخادم فيعمل في مكان لا يبلغه — وذلك الفرق هو سبب وجود الخلفية كله.
-
2
Your first file that thinks / أول ملف لك يفكّر
A PHP file is an HTML file that can decide things on its way out. That framing — HTML with holes in it that get filled before sending — is the one that makes everything else in this course straightforward.
ملف PHP ملفُّ HTML يستطيع أن يقرر أشياء في طريقه إلى الخارج. وذلك التصوّر — HTML فيه فجوات تُملأ قبل الإرسال — هو ما يجعل كل ما عداه في هذه الدورة يسيرًا.
-
3
What happens between the click and the page / ما يحدث بين الضغطة والصفحة
The web course showed you the request travelling. This is what happens at the far end of it: a server picks a file, runs it, and sends back whatever it printed. Knowing that sequence is what makes errors readable.
أرتك دورة الويب الطلبَ وهو يسافر. وهذا ما يحدث في طرفه البعيد: يختار خادمٌ ملفًا، ويشغّله، ويعيد ما طبعه. ومعرفة ذلك التتابع هي ما يجعل الأخطاء مقروءة.
2 The language, properlyاللغة، على وجهها 4
-
4
One structure that does almost everything / بنية واحدة تفعل كل شيء تقريبًا
PHP has one collection type where most languages have two, and it carries an enormous amount of the work. Learning the array and about a dozen functions that operate on it is most of learning the language.
في PHP نوع تجميع واحد حيث لمعظم اللغات نوعان، وهو يحمل قدرًا هائلًا من العمل. وتعلّم المصفوفة ونحو اثنتي عشرة دالة تعمل عليها هو معظم تعلّم اللغة.
-
5
Naming a piece of work / تسمية قطعة عمل
A function is the smallest unit you can name, test and trust. The discipline that matters is not writing them — it is making each one depend only on what it was given, so that reading its first line tells you everything it can touch.
الدالة أصغر وحدة تستطيع تسميتها واختبارها والوثوق بها. والانضباط المهم ليس كتابتها — بل جعل كلٍّ منها تعتمد على ما أُعطيته فقط، حتى تخبرك قراءة سطرها الأول بكل ما تستطيع مسّه.
-
6
Where PHP will trip you / حيث ستتعثّر بك PHP
Most of PHP's bad reputation comes from one design decision: comparing two things of different types tries to make them match first. Learn the four rules on this page and that entire category of bug stops happening to you.
معظم سمعة PHP السيئة من قرار تصميمي واحد: مقارنة شيئين من نوعين مختلفين تحاول التوفيق بينهما أولًا. تعلّم القواعد الأربع في هذه الصفحة فيكفّ ذلك الصنف من العلل عن الحدوث لك.
-
7
One file, one job / ملف واحد، عمل واحد
Everything so far fits in one file. Real applications do not, and the mechanism that splits them is
require— which is also, when handed a value from a visitor, one of the most dangerous things in the language.كل ما سبق يسع ملفًا واحدًا. والتطبيقات الحقيقية لا تسعه، والآلية التي تقسّمها هي
require— وهي أيضًا، حين تُسلَّم قيمة من زائر، من أخطر ما في اللغة.
3 Handling a requestمعالجة الطلب 4
-
8
Receiving what a visitor sent / استقبال ما أرسله الزائر
A form is the first moment your server hears from someone who is not you. Everything about handling it follows from one fact: the form you wrote is not the form they submitted, and you have no way to know what they changed.
النموذج أول لحظة يسمع فيها خادمك من شخص ليس أنت. وكل ما يتعلق بمعالجته يتبع حقيقة واحدة: أن النموذج الذي كتبته ليس النموذج الذي أرسلوه، ولا سبيل لك إلى معرفة ما غيّروه.
-
9
Text that turns into markup / نصٌّ يتحول إلى وسوم
Printing what a visitor typed straight into a page hands them control of that page — for everyone who reads it afterwards, not just for themselves. One function fixes it, and the discipline is applying it every single time.
طباعة ما كتبه زائر مباشرةً في صفحة تسلّمه التحكم في تلك الصفحة — لكل من يقرؤها بعده، لا له وحده. ودالة واحدة تصلح ذلك، والانضباط هو تطبيقها في كل مرة دون استثناء.
-
10
Staying signed in / البقاء مسجَّلًا
Nothing survives a request, so being "signed in" has to be reconstructed from scratch on every page. A session is how: a cookie holding a meaningless id, and a file on the server that the id points at.
لا ينجو شيء من طلب، فلا بد من إعادة بناء «تسجيل الدخول» من الصفر في كل صفحة. والجلسة هي الكيفية: كوكيز يحمل معرّفًا بلا معنى، وملف على الخادم يشير إليه المعرّف.
-
11
Storing a password you can never read / تخزين كلمة سر لا تستطيع قراءتها أبدًا
You will one day hold other people's passwords, and many of them will be the same password they use for their email. PHP gives you two functions that make this safe, and the whole job is using them and adding nothing.
ستحمل يومًا كلمات سر لغيرك، وكثير منها هو نفسه ما يستعملونه لبريدهم. وتعطيك PHP دالتين تجعلان هذا آمنًا، والعمل كله هو استعمالهما وألا تضيف شيئًا.
4 Where the data livesأين تعيش البيانات 3
-
12
Talking to a database / التحدث إلى قاعدة بيانات
Files stop being enough the moment two requests want to change the same thing at the same time. PDO is how PHP connects to a database, and four settings on that connection decide whether your errors are visible and your queries are safe.
تكفّ الملفات عن الكفاية لحظة يريد طلبان تغيير الشيء نفسه في الوقت نفسه. وPDO هي كيفية اتصال PHP بقاعدة بيانات، وأربعة إعدادات على ذلك الاتصال تقرر أتكون أخطاؤك مرئية واستعلاماتك آمنة.
-
13
Never build a query out of text / لا تبنِ استعلامًا من نص أبدًا
SQL injection is thirty years old, still in the top handful of causes of real breaches, and closed completely by one habit: send the query and the values to the database separately, and never join them together yourself.
حقن SQL عمره ثلاثون سنة، وما زال من أكبر أسباب الاختراقات الحقيقية، ويُغلق تمامًا بعادة واحدة: أرسل الاستعلام والقيم إلى قاعدة البيانات منفصلين، ولا تصلهما بنفسك أبدًا.
-
14
Deciding where a fact lives / تقرير أين تعيش الحقيقة
Schema decisions outlive every line of code around them. The rule that prevents most pain is boring and absolute: each fact is stored once, in one place, and everywhere else points at it.
قرارات المخطط تعيش أطول من كل سطر كود حولها. والقاعدة التي تمنع معظم الألم مملّة ومطلقة: كل حقيقة تُخزَّن مرة واحدة، في مكان واحد، وكل ما عداه يشير إليها.
5 Togetherمعًا 2
-
15
What breaks, and who gets to know / ما ينكسر، ومن يحق له أن يعلم
A visitor should see an apology and a way forward. You should see a stack trace. On a development machine those are the same screen, and in production they must never be — which is one setting, and the commonest way a PHP site leaks its own internals.
ينبغي أن يرى الزائر اعتذارًا وطريقًا إلى الأمام. وأن ترى أنت أثر المكدس. وعلى جهاز التطوير هما الشاشة نفسها، وفي الإنتاج يجب ألا يكونا كذلك أبدًا — وهو إعداد واحد، وأشيع طريقة يفشي بها موقع PHP دواخله.
-
16
Putting the fifteen lessons together / جمع الدروس الخمسة عشر معًا
Everything in this course is one page: a request arrives, something is decided, a page goes back. This lesson assembles the pieces in the order they run, and then points you at a working application you can read — the one you are reading this on.
كل ما في هذه الدورة صفحة واحدة: يصل طلب، ويُقرَّر شيء، وتعود صفحة. وهذا الدرس يركّب القطع بترتيب عملها، ثم يشير إلى تطبيق عامل تستطيع قراءته — الذي تقرأ هذا عليه.