Chapterبەش 1 · Lectureوانە 1.3
HTTP and the Request–Response CycleHTTP و سووڕی داواکاری و وەڵام
What HTTP and HTTPS are, what is inside a request and a response, why PHP is a server-side language, the operational trail of a PHP page on the server, how a browser loads a whole page, and why HTTP is stateless.
و چین، چی لەناو و ، بۆچی زمانێکی ، ڕێچکەی کارکردنی لاپەڕەیەکی لەسەر ، چۆن تەواوی لاپەڕەیەک دەکاتەوە و بۆچی .
What you will learnچی فێر دەبیت
- Explain what HTTP and HTTPS are and name the parts of a request and a response.
- Read common status codes such as 200, 302, 404 and 500.
- Explain why PHP is server-side and describe the operational trail of a PHP page.
- Describe every step of loading a web page, including the separate requests for CSS, pictures and scripts.
- Explain what stateless means and how cookies and sessions keep state.
- ڕوونی بکەیتەوە و چین و ناوی بەشەکانی و بهێنیت.
- وەک 200، 302، 404 و 500 بخوێنیتەوە.
- ڕوونی بکەیتەوە بۆچی و ڕێچکەی کارکردنی لاپەڕەیەکی باس بکەیت.
- هەموو هەنگاوێکی کردنەوەی باس بکەیت، لەگەڵ بۆ ، وێنە و .
- ڕوونی بکەیتەوە واتای چییە و و چۆن دۆخ دەهێڵنەوە.
A short conversation, millions of times a dayگفتوگۆیەکی کورت، ملیۆنان جار لە ڕۆژێکدا
Every time you open a web page, your browser and a web server have a short conversation. The browser asks; the server answers. The rules of this conversation are called HTTP. When you write PHP, you are writing the server's side of this conversation, so it is worth knowing it well.
هەر جارێک دەکەیتەوە، و گفتوگۆیەکی کورت دەکەن. داوا دەکات؛ دەداتەوە. یاساکانی ئەم گفتوگۆیە پێیان دەوترێت . کاتێک دەنووسیت، بەشی ئەم گفتوگۆیە دەنووسیت، بۆیە شایەنی ئەوەیە بە باشی بیناسیت.
In this lecture you will learn:
لەم وانەیەدا فێری ئەمانە دەبیت:
- What HTTP and HTTPS are, and what a request and a response look like inside.
- Why PHP is called a server-side language: what happens to a
.phpfile on the server (the "operational trail"). - Everything that happens after the HTML arrives in the browser.
- Why HTTP is stateless, and how cookies and sessions help a website remember you.
- و چین و و لە ناوەوە چۆنن.
- بۆچی پێی دەوترێت زمانێکی : فایلێکی
.phpلەسەر چی بەسەر دێت («ڕێچکەی کارکردن»). - هەموو ئەو شتانەی دوای گەیشتنی بۆ ڕوودەدەن.
- بۆچی و و چۆن یارمەتیی دەدەن تۆ بناسێتەوە.
What is HTTP?HTTP چییە؟
HTTP stands for HyperText Transfer Protocol. It is the protocol used for communication between a client (usually a web browser) and a server on the World Wide Web. In simple words: HTTP is the language browsers and servers use to ask for and send pages.
کورتکراوەی HyperText Transfer Protocolـە. ئەو کە بۆ پەیوەندیکردن لە نێوان (بە زۆری ) و لەسەر بەکار دێت. بە زمانێکی سادە: ئەو زمانەیە کە و بۆ داواکردن و ناردنی لاپەڕەکان بەکاری دەهێنن.
The that browsers and servers use to ask for and send . Every exchange is one and one .
کە و بۆ داواکردن و ناردنی بەکاری دەهێنن. هەر ئاڵوگۆڕێک لە یەک و یەک پێکدێت.
The conversation always has the same shape:
گفتوگۆکە هەمیشە هەمان شێوەی هەیە:
- The client always starts. It sends a request: "please give me
/hello.php". - The server sends back exactly one response: the page, or a message that something went wrong.
- Then the conversation is over. For the next page, a new request starts a new conversation.
- هەمیشە دەست پێدەکات. دەنێرێت: «تکایە
/hello.phpم بدەرێ». - تەنها یەک دەنێرێتەوە: لاپەڕەکە، یان پەیامێک کە شتێک نادروست ڕۆیشتووە.
- پاشان گفتوگۆکە تەواو دەبێت. بۆ لاپەڕەی داهاتوو، نوێ گفتوگۆیەکی نوێ دەست پێدەکات.
HTTP is like ordering at a tea house. You (the client) say to the waiter: "one tea, without sugar, please" (the request). The waiter (the server) brings your tea, or says "sorry, we have no tea today" (the response). Both sides know the polite, fixed way to order and to answer, so it works with any customer and any waiter.
وەک داواکردنی چا لە چایخانەیەک وایە. تۆ () بە چایچییەکە دەڵێیت: «تکایە چایەک بێ شەکر» (). چایچییەکە () چاکەت بۆ دەهێنێت، یان دەڵێت «ببورە، ئەمڕۆ چامان نییە» (). هەردوولا ڕێگای ڕێکوپێک و دیاریکراوی داواکردن و دەزانن، بۆیە لەگەڵ هەر کڕیارێک و هەر چایچییەک کار دەکات.
Where the analogy stops workingسنووری ئەم نموونەیە
A good waiter remembers you after a few visits. HTTP does not: every request is new to the server. See HTTP is stateless.
چایچییەکی باش دوای چەند سەردانێک دەتناسێتەوە. وا نییە: هەموو بۆ نوێیە. سەیری HTTP بێدۆخە بکە.
What is HTTP?HTTP چییە؟
HTTPS: the secure versionHTTPS: وەشانە پارێزراوەکە
Plain HTTP sends everything as readable text. Anyone between the browser and the server (for example, someone on the same public Wi-Fi) could read the pages, the form data and even your password, or change them on the way.
سادە هەموو شتێک وەک دەقی خوێنراوە دەنێرێت. هەر کەسێک لە نێوان و (بۆ نموونە کەسێک لەسەر هەمان Wi-Fiـی گشتی) دەتوانێت لاپەڕەکان، دراوەکانی و تەنانەت بخوێنێتەوە، یان لە نێوەڕێدا بیانگۆڕێت.
HTTPS is HTTP protected with (a system called TLS). The browser shows a padlock next to the address, and the URL starts with https://. HTTPS normally uses port 443 instead of 80. Today almost every website uses HTTPS, and any page with a login or a form must use it.
بریتییە لە کە بە پارێزراوە (بە سیستەمێک بە ناوی TLS). قوفڵێک لە تەنیشت ناونیشانەکە پیشان دەدات و بە https:// دەست پێدەکات. بە ئاسایی 443 لە جیاتی 80 بەکار دەهێنێت. ئەمڕۆ نزیکەی هەموو بەکار دەهێنن و هەر لاپەڕەیەک کە یان تێدا بێت دەبێت بەکاری بهێنێت.
The secure version of . It uses TLS , so nobody between the browser and the server can read or change the data.
وەشانە پارێزراوەکەی . TLS بۆ بەکار دەهێنێت، بۆیە هیچ کەسێک لە نێوان تۆڕگەڕ و ڕاژەکاردا ناتوانێت دراوەکان بخوێنێتەوە یان بیانگۆڕێت.
See why plain HTTP can be read by an attacker, and how HTTPS encrypts the conversation between browser and server.
ببینە بۆچی هێرشبەرێک دەتوانێت ناوەڕۆکی ئاسایی بخوێنێتەوە و چۆن بە گفتوگۆی نێوان و دەپارێزێت.
Whole video: HTTP vs HTTPS, then SSL/TLS basics
هەموو ڤیدیۆکە: جیاوازیی و ، پاشان بنەماکانی SSL/TLS.
Inside a request and a responseناوەوەی داواکارییەک و وەڵامێک
A request and a response are short text messages. You never type them yourself: the browser writes the request, and the web server (with PHP) writes the response. But reading them once makes everything else in this course easier.
و پەیامی دەقیی کورتن. هەرگیز خۆت نایاننووسیت: دەنووسێت و (لەگەڵ ) دەنووسێت. بەڵام ئەگەر جارێک بیانخوێنیتەوە، هەموو شتێکی تری ئەم کۆرسە ئاسانتر دەبێت.
Inside a request and a responseناوەوەی داواکارییەک و وەڵامێک
The requestداواکارییەکە
GET /hello.php HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
Accept: text/html
Accept-Language: ckb, enExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
The request line: the method
GET("give me"), the path/hello.phpand the HTTP version.دێڕی :
GET(«بمدەرێ»)،/hello.phpو وەشانی .- Lineدێڕی 2
Hostnames the website. One server can keep many websites, so it must know which one you want.Hostناوی دەڵێت. یەک دەتوانێت چەندین هەڵبگرێت، بۆیە دەبێت بزانێت تۆ کامیانت دەوێت.- Lineدێڕی 3
User-Agentsays which browser and operating system is asking.User-Agentدەڵێت کام و کام داوا دەکات.- Lineدێڕی 4-5
Acceptsays what kind of data the browser expects (here HTML).Accept-Languagelists the languages the user prefers (ckbis Central Kurdish).Acceptدەڵێت چاوەڕێی چ جۆرە دراوەیەک دەکات (لێرەدا ).Accept-Languageئەو زمانانە دەژمێرێت کە بەکارهێنەر پێی باشترە (ckbواتە کوردیی ناوەندی).- Lineدێڕی 6
An empty line ends the headers. A
GETrequest has no body after it.دێڕێکی بەتاڵ کۆتایی بە دەهێنێت.
GETلە دوای ئەوە لاشەی نییە.
The first word of the request is the HTTP method. In this course you will use two of them:
یەکەم وشەی ـە. لەم کۆرسەدا دوویان بەکار دەهێنیت:
| Method | Meaningواتا | Where the data goesدراوەکان لە کوێ دەڕۆن |
|---|---|---|
GET | "Give me this page." Used when you type a URL or click a link.«ئەم لاپەڕەیەم بدەرێ.» کاتێک دەنووسیت یان کرتە لە دەکەیت بەکار دێت. | In the URL, as a query string: ?id=5لەناو ، وەک : ?id=5 |
POST | "Here is some data for you." Used by forms that send or save data.«ئەمە هەندێک دراوەیە بۆ تۆ.» بەکاری دەهێنن کاتێک دراوە دەنێرن یان پاشەکەوت دەکەن. | In the body of the request, after the headersلە لاشەی ، دوای |
You will use both of them with PHP forms in Form handling with GET and POST.
هەردووکیان لەگەڵ لە وانەی مامەڵەکردن لەگەڵ فۆرم بە GET و POST بەکار دەهێنیت.
Inside a request and a responseناوەوەی داواکارییەک و وەڵامێک
The responseوەڵامەکە
HTTP/1.1 200 OK
Date: Fri, 16 Oct 2026 10:00:00 GMT
Server: Apache
Content-Type: text/html; charset=UTF-8
Content-Length: 142
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Welcome</h1>
<p>Hello, Aram!</p>
<p>2 + 3 = 5</p>
</body>
</html>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
The status line: the version, the status code
200and its reasonOK. It tells the browser how the request went.دێڕی دۆخ: وەشان،
200و هۆکارەکەیOK. بە دەڵێت چۆن ڕۆیشت.- Lineدێڕی 3
Servernames the web server program, here Apache.Serverناوی دەڵێت، لێرەدا .- Lineدێڕی 4
Content-Typesays what the body is: an HTML page written in UTF-8, the character set that can show Kurdish letters.Content-Typeدەڵێت لاشەکە چییە: لاپەڕەیەکی کە بە UTF-8 نووسراوە، ئەو کۆمەڵە پیتەی دەتوانێت پیتە کوردییەکان پیشان بدات.- Lineدێڕی 5
Content-Lengthis the size of the body in bytes (here 142).Content-Lengthقەبارەی لاشەکەیە بە بایت (لێرەدا 142).- Lineدێڕی 7-17
The body: the HTML that PHP produced. This is the only part the browser draws.
لاشە: ئەو بەرهەمی هێناوە. ئەمە تاکە بەشە کە دەیکێشێت.
Inside a request and a responseناوەوەی داواکارییەک و وەڵامێک
Status codesکۆدەکانی دۆخ
When the server cannot find the file, it still sends a response, but with an error status code and a short error page:
کاتێک فایلەکە نادۆزێتەوە، هەر دەنێرێت، بەڵام بە و لاپەڕەیەکی کورتی :
HTTP/1.1 404 Not Found
Date: Fri, 16 Oct 2026 10:00:05 GMT
Server: Apache
Content-Type: text/html; charset=UTF-8
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>| Codeکۆد | Nameناو | What it meansواتای چییە |
|---|---|---|
200 | OK | Everything worked; the body holds the page.هەموو شتێک باش ڕۆیشت؛ لاشەکە لاپەڕەکەی تێدایە. |
301 | Moved Permanently | The page has a new address forever; the browser goes there.لاپەڕەکە بۆ هەمیشە ناونیشانێکی نوێی هەیە؛ دەچێتە ئەوێ. |
302 | Found | A temporary : go to another address this time. PHP's header("Location: ...") sends this. کاتی: ئەم جارە بچۆ بۆ ناونیشانێکی تر. header("Location: ...")ی ئەمە دەنێرێت. |
403 | Forbidden | The file exists, but you are not allowed to see it.فایلەکە هەیە، بەڵام ڕێگەت پێنادرێت بیبینیت. |
404 | Not Found | There is no file at this path. Check the spelling of the URL.هیچ فایلێک لەم نییە. نووسینی بپشکنە. |
500 | Internal Server Error | Something broke on the server, for example a fatal error in your PHP code.شتێک لەسەر تێکچوو، بۆ نموونە لە کۆدی . |
PHP: a server-side languagePHP: زمانێکی ڕاژەبەند
PHP is called a server-side language because its code runs on the web server, not in the browser. Look at the journey of one PHP page:
پێی دەوترێت زمانێکی ، چونکە کۆدەکەی لەسەر کار دەکات، نەک لە . سەیری گەشتی یەک لاپەڕەی بکە:
- The browser asksتۆڕگەڕەکە داوا دەکات
The browser on the user's computer sends an HTTP request for the page
hello.php.لەسەر کۆمپیوتەری بەکارهێنەر بۆ لاپەڕەی
hello.phpدەنێرێت. - The server processesڕاژەکارەکە کار لەسەر دەکات
The web server finds
hello.php. The PHP interpreter runs the code inside it ("processing"). Whatever the code prints becomes HTML.hello.phpدەدۆزێتەوە. کۆدەکەی ناوی جێبەجێ دەکات («کارلەسەرکردن»). هەر شتێک کۆدەکە چاپی بکات دەبێت بە . - An HTML page comes backلاپەڕەیەکی HTML دەگەڕێتەوە
The server sends back an HTML page. The browser draws it. The PHP code itself stays on the server.
لاپەڕەیەکی دەنێرێتەوە. دەیکێشێت. خودی کۆدی لەسەر دەمێنێتەوە.
Explains the client and the server computers, why HTML, CSS and JavaScript run in the browser while PHP runs on the server, and front end vs back end.
و ڕوون دەکاتەوە، بۆچی ، و لە کار دەکەن بەڵام لەسەر کار دەکات، هەروەها جیاوازیی و .
Watch 0:42–9:03, client-side vs server-side code
لە 0:42 تا 9:03 سەیر بکە: جیاوازیی کۆدی و کۆدی .
PHP: a server-side languagePHP: زمانێکی ڕاژەبەند
Three views of the same pageسێ دیمەنی هەمان لاپەڕە
Here is a small PHP page. Compare what you write, what the server sends, and what the visitor sees.
ئەمە لاپەڕەیەکی بچووکی . بەراوردی بکە: ئەوەی تۆ دەینووسیت، ئەوەی دەینێرێت و ئەوەی سەردانکەر دەیبینێت.
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Welcome</h1>
<?php
$name = "Aram";
echo "<p>Hello, $name!</p>\n";
echo "<p>2 + 3 = " . (2 + 3) . "</p>\n";
?>
</body>
</html>Welcome Hello, Aram! 2 + 3 = 5
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Welcome</h1>
<p>Hello, Aram!</p>
<p>2 + 3 = 5</p>
</body>
</html>Verified with PHP 8. Notice that the HTML has no PHP code in it: <?php, $name and echo are gone.
بە PHP 8 تاقی کراوەتەوە. سەرنج بدە هیچ کۆدێکی تێدا نییە: <?php، $name و echo نەماون.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-7
Plain HTML. PHP does not touch it; it is sent exactly as written.
سادە. دەستی لێ نادات؛ هەروەک خۆی دەنێردرێت.
- Lineدێڕی 8-12
The PHP block between
<?phpand?>. The server runs it: it stores the name Aram in$name, andechoprints two paragraphs of HTML.بلۆکی لە نێوان
<?phpو?>. جێبەجێی دەکات: ناوی ئارام لە$nameدا هەڵدەگرێت وechoدوو بڕگەی چاپ دەکات.- Lineدێڕی 11
2 + 3is calculated on the server; the browser receives only the result5.2 + 3لەسەر هەژمار دەکرێت؛ تەنها ئەنجامەکەی وەردەگرێت:5.
If you choose View Page Source in the browser (Ctrl+U), you see the HTML of view 2, never the PHP of view 1. That is why visitors cannot read your PHP code, and why passwords written inside PHP code stay on the server.
ئەگەر لە View Page Source هەڵبژێریت (Ctrl+U)، دیمەنی ٢ دەبینیت، هەرگیز دیمەنی ١ نابینیت. بۆیە سەردانکەران ناتوانن کۆدی بخوێننەوە و بۆیە هەر لەناو کۆدی بنووسرێت، لەسەر دەمێنێتەوە.
The operational trail: inside the serverڕێچکەی کارکردن: لەناو ڕاژەکاردا
What happens when you actually ask for a URL in your browser, before you get HTML back to you? The course calls this path the operational trail. Let us follow a request for hello.php inside the server.
کاتێک بە ڕاستی لە داوای دەکەیت، پێش ئەوەی بگەڕێتەوە بۆت، چی ڕوودەدات؟ کۆرسەکە بەم ڕێگایە دەڵێت ڕێچکەی کارکردن (operational trail). با بەدوای بۆ hello.php لەناو بکەوین.
- Requestداواکاری
The browser sends a request for
/hello.phpto the server.بۆ
/hello.phpدەنێرێت بۆ . - Find the pageلاپەڕەکە بدۆزەرەوە
Apache looks for the file
hello.phpin its document folder (in XAMPP, thehtdocsfolder). If it is not there, Apache answers404 Not Foundand the trail ends here.لە بەڵگەنامەکانیدا (لە ، ) بەدوای فایلی
hello.phpدا دەگەڕێت. ئەگەر لەوێ نەبێت،404 Not Foundدەداتەوە و ڕێچکەکە لێرە کۆتایی دێت. - Hand it to PHPبیدە بە PHP
The file name ends in
.php, so Apache does not send the file as it is. It hands it to the PHP interpreter.ناوی فایلەکە بە
.phpکۆتایی دێت، بۆیە فایلەکە هەروەک خۆی نانێرێت. دەیدات بە . - Process PHPجێبەجێکردنی PHP
PHP runs the code from top to bottom. If the page needs data (a list of products, a user's name), PHP reads it from, or saves it to, a database such as MySQL.
کۆدەکە لە سەرەوە بۆ خوارەوە جێبەجێ دەکات. ئەگەر لاپەڕەکە پێویستی بە دراوە بێت (لیستی کاڵاکان، ناوی بەکارهێنەرێک)، لە وەک دەیخوێنێتەوە یان تێیدا پاشەکەوتی دەکات.
- Return HTMLHTML بنێرەوە
Everything PHP printed is now plain HTML. It goes back to Apache.
هەموو ئەو شتانەی چاپی کردوون ئێستا سادەن. دەگەڕێنەوە بۆ .
- Responseوەڵام
Apache sends the HTML to the browser in an HTTP response, and the browser draws the page.
لە دەنێرێت بۆ و لاپەڕەکە دەکێشێت.
The operational trail: inside the serverڕێچکەی کارکردن: لەناو ڕاژەکاردا
Why the .php extension mattersبۆچی پاشگری فایلی .php گرنگە
| File the browser asks forئەو فایلەی داوای دەکات | What the server does چی دەکات |
|---|---|
about.html, style.css, logo.png | Apache sends the file exactly as it is. PHP is not involved. فایلەکە هەروەک خۆی دەنێرێت. بەشدار نییە. |
hello.php | Apache gives the file to PHP, PHP runs it, and only its HTML output is sent. فایلەکە دەدات بە ، جێبەجێی دەکات و تەنها دەنێردرێت. |
After the HTML arrives: loading the whole pageدوای گەیشتنی HTML: کردنەوەی تەواوی لاپەڕەکە
A real web page is more than one HTML file. It also needs CSS, pictures and JavaScript. Here is the whole story, from pressing Enter to a finished page:
ڕاستەقینە لە یەک فایلی زیاترە. پێویستی بە ، وێنە و هەیە. ئەمە هەموو چیرۆکەکەیە، لە داگرتنی Enterـەوە تا لاپەڕەیەکی تەواو:
- You press EnterEnter دادەگریت
You type a URL and press Enter. The browser sends a request to the server that hosts the website. The request says what kind of data the browser expects to receive, such as HTML, images or other media (the
Acceptheader).دەنووسیت و Enter دادەگریت. دەنێرێت بۆ ئەو هەڵدەگرێت. دەڵێت چاوەڕێی وەرگرتنی چ جۆرە دراوەیەک دەکات، وەک ، وێنە یان میدیای تر (سەردێڕی
Accept). - The server processes the requestڕاژەکارەکە کار لەسەر داواکارییەکە دەکات
The server receives the request and starts to process it. If it finds the page, it sends the HTML document back in a response. For a
.phppage it first runs the PHP code (the operational trail above).وەردەگرێت و دەست دەکات بە کارکردن لەسەری. ئەگەر لاپەڕەکە بدۆزێتەوە، بەڵگەنامەی لە دەنێرێتەوە. بۆ لاپەڕەیەکی
.php، سەرەتا کۆدی جێبەجێ دەکات (ڕێچکەی کارکردنی سەرەوە). - Or an errorیان هەڵە
If the server cannot find the page, or something else goes wrong, it sends a response with an error message and an error status code, such as
404 Not Foundor500 Internal Server Error.ئەگەر لاپەڕەکە نەدۆزێتەوە، یان شتێکی تر نادروست بڕوات، دەنێرێت کە پەیامی و تێدایە، وەک
404 Not Foundیان500 Internal Server Error. - The browser reads the HTMLتۆڕگەڕەکە HTMLـەکە دەخوێنێتەوە
The browser processes the HTML file, the backbone of every web page. It reads the HTML and builds a visual version of the page on your screen.
کار لەسەر فایلی دەکات، کە ئێسکی پشتی هەموو . دەخوێنێتەوە و وێنەیەکی بینراوی لاپەڕەکە لەسەر شاشەکەت دروست دەکات.
- The browser fetches the extra filesتۆڕگەڕەکە فایلە زیادەکان دەهێنێت
While reading, the browser finds tags such as
<link>(CSS),<img>(pictures, videos) and<script>(JavaScript). For each of these files it sends a separate request and gets a separate response.لە کاتی خوێندنەوەدا، وەک
<link>()،<img>(وێنە، ڤیدیۆ) و<script>() دەدۆزێتەوە. بۆ هەر یەک لەم فایلانە جیا دەنێرێت و جیا وەردەگرێتەوە. - The browser runs the JavaScriptتۆڕگەڕەکە JavaScript جێبەجێ دەکات
Finally, the browser runs any JavaScript code on the page, so the page can react to the user and do dynamic things.
لە کۆتاییدا، هەر کۆدێکی کە لە لاپەڕەکەدا هەبێت جێبەجێ دەکات، بۆ ئەوەی لاپەڕەکە کاردانەوەی بۆ بەکارهێنەر هەبێت و کاری داینامیک بکات.
After the HTML arrives: loading the whole pageدوای گەیشتنی HTML: کردنەوەی تەواوی لاپەڕەکە
One request for every fileداواکارییەک بۆ هەر فایلێک
HTTP is statelessHTTP بێدۆخە
HTTP is a stateless protocol: it keeps no information about earlier requests or responses. Each request–response pair is independent of all the pairs before it.
ـە: هیچ زانیارییەک دەربارەی و هەڵناگرێت. هەر جووتێکی – سەربەخۆیە لە هەموو جووتەکانی پێش خۆی.
A stateless does not remember earlier requests: each is handled on its own. is stateless, so websites use and to remember users.
واتە هیچ داواکارییەکی پێشووی لە بیر نییە: هەر بە جیا مامەڵەی لەگەڵ دەکرێت. بێدۆخە، بۆیە تۆڕگەکان و بەکار دەهێنن بۆ ئەوەی بەکارهێنەرەکانیان بناسنەوە.
For example, when you visit a website and click a link, the server receives a new request for the new page, with no information about the page you were on. The server does not "remember" anything about the previous request: not the information you typed into a form, and not anything else you did on the site.
بۆ نموونە، کاتێک سەردانی دەکەیت و کرتە لە دەکەیت، نوێ بۆ لاپەڕە نوێیەکە وەردەگرێت، بەبێ هیچ زانیارییەک دەربارەی ئەو لاپەڕەیەی پێشتر لەسەری بوویت. هیچ شتێک لە «لە بیر نییە»: نە ئەو زانیارییانەی لە نووسیوتن و نە هیچ کارێکی تر کە لەسەر کردووتە.
You can see this with PHP. Every request starts a fresh run of the script, with fresh variables:
دەتوانیت ئەمە بە ببینیت. هەموو لە سەرەتاوە کارپێدەکاتەوە، بە :
<?php
$visits = 0; // every request starts here
$visits++; // add one
echo "<p>Visits: $visits</p>";Visits: 1
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Visits: 1</p>We ran the script twice with PHP 8: both runs printed Visits: 1. Reload as often as you like; it never says 2.
دوو جار بە PHP 8 کارپێکرا: هەردوو جار Visits: 1ـی چاپ کرد. هەر چەند جار دەتەوێت نوێی بکەرەوە؛ هەرگیز ناڵێت 2.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2
Each request creates
$visitsagain and sets it to 0.هەموو
$visitsدووبارە دروست دەکاتەوە و دەیکات بە 0.- Lineدێڕی 3
++adds one, so$visitsbecomes 1.++یەک زیاد دەکات، بۆیە$visitsدەبێت بە 1.- Lineدێڕی 4
The page prints 1. When the response is sent, the script ends and
$visitsis gone.لاپەڕەکە 1 چاپ دەکات. کاتێک دەنێردرێت، کۆتایی دێت و
$visitsنامێنێت.
HTTP is statelessHTTP بێدۆخە
How websites remember you: cookies and sessionsتۆڕگەکان چۆن دەتناسنەوە: کووکییەکان و سێشنەکان
To keep state (to remember things) between requests, web developers use two techniques:
بۆ هێشتنەوەی دۆخ (لەبیرکردنی شتەکان) لە نێوان ، گەشەپێدەرانی وێب دوو ڕێگا بەکار دەهێنن:
- Cookies are small pieces of data stored on the client's computer. The server asks the browser to keep a cookie, and the browser sends it back with every later request to that site.
- Server-side session management stores the session data on the server. The browser keeps only a short session ID (usually in a cookie), and the server uses it to find that visitor's data.
- پارچە دراوەی بچووکن کە لەسەر کۆمپیوتەری هەڵدەگیرێن. داوا لە دەکات هەڵبگرێت و لەگەڵ هەموو دواتر بۆ ئەو دەینێرێتەوە.
- بەڕێوەبردنی لە لای دراوەکانی لەسەر هەڵدەگرێت. تەنها کورت دەهێڵێتەوە (زۆرجار لە ) و بەکاری دەهێنێت بۆ دۆزینەوەی دراوەکانی ئەو سەردانکەرە.
A busy bakery serves hundreds of customers and cannot remember faces. When you order a birthday cake, the baker gives you a small ticket with a number (a cookie with a session ID) and writes your order in a notebook under that number (the session on the server). When you come back, you show the ticket, and the baker finds your order at once.
نانەواخانەیەکی قەرەباڵغ خزمەتی سەدان کڕیار دەکات و ناتوانێت ڕووخسارەکان لە بیر بگرێت. کاتێک کێکێکی ڕۆژی لەدایکبوون داوا دەکەیت، نانەواکە پسوولەیەکی بچووکت دەداتێ کە ژمارەیەکی لەسەرە ( کە تێدایە) و داواکەت لە دەفتەرێکدا لە ژێر ئەو ژمارەیەدا دەنووسێت ( لەسەر ). کاتێک دەگەڕێیتەوە، پسوولەکە پیشان دەدەیت و نانەواکە دەستبەجێ داواکەت دەدۆزێتەوە.
Where the analogy stops workingسنووری ئەم نموونەیە
Anyone who steals your ticket can collect your cake. In the same way, a stolen session ID lets someone act as you, which is one reason why logins must use HTTPS.
هەر کەسێک پسوولەکەت بدزێت دەتوانێت کێکەکەت ببات. بە هەمان شێوە، دزراو ڕێگە بە کەسێک دەدات خۆی بکات بە تۆ و ئەمە یەکێکە لە هۆکارەکانی ئەوەی بۆچی دەبێت بەکار بهێنێت.
See how a server remembers you: it gives your browser a session ID and keeps your data on the server.
ببینە چۆن تۆ دەناسێتەوە: دەداتە و لەسەر خۆی هەڵدەگرێت.
Watch 0:00–4:41, session IDs; stops before the JWT part
لە 0:00 تا 4:41 سەیر بکە: ؛ پێش بەشی JWT ڕادەوەستێت.
HTTP is statelessHTTP بێدۆخە
Why is HTTP stateless?بۆچی HTTP بێدۆخە؟
Why is HTTP designed like this? Because a server that remembers nothing is simple, and any server can answer any request. A big website can share millions of visitors among many servers. In short, being stateless allows greater scalability and a simpler implementation, but it also means extra work to keep state across several requests.
بۆچی بەم شێوەیە دیزاین کراوە؟ چونکە کە هیچ شتێکی لە بیر نەبێت سادەیە و هەر دەتوانێت هەر بداتەوە. گەورە دەتوانێت ملیۆنان سەردانکەر بەسەر چەندین دابەش بکات. بە کورتی، بوون ڕێگە بە فراوانبوونی زیاتر و دروستکردنێکی سادەتر دەدات، بەڵام واتای کاری زیادەشە بۆ هێشتنەوەی دۆخ لە نێوان چەند .
Common mistakesئەو هەڵانەی زۆرجار دەکرێن
- Thinking the browser sends PHP code to the server. It sends a request for a page. The PHP code is already on the server.
- Opening a
.phpfile by double-clicking it. PHP only runs through the web server: usehttp://localhost/..., notfile:///.... - Expecting a variable to keep its value on the next page. HTTP is stateless and every request starts the script again. Use a session or a cookie to remember things.
- Thinking one response carries the whole page. The HTML comes in one response; every CSS file, picture and script needs its own request.
- Treating
404as a bug in your PHP code.404 Not Foundmeans the server found no file at that path: check the file name, the folder and the URL. A PHP error gives500or an error message instead. - Sending passwords over plain
http://. Any page with a login or a form must usehttps://.
- وا بزانیت کۆدی دەنێرێت بۆ . بۆ لاپەڕەیەک دەنێرێت. کۆدی پێشتر لەسەر .
- کردنەوەی فایلێکی
.phpبە دوو کرتە. تەنها لە ڕێگەی کار دەکات:http://localhost/...بەکار بهێنە، نەکfile:///.... - چاوەڕوانیی ئەوەی لە لاپەڕەی داهاتوودا بهێڵێتەوە. و هەموو لە سەرەتاوە دەست پێدەکاتەوە. بۆ لەبیرکردنی شتەکان یان بەکار بهێنە.
- وا بزانیت یەک هەموو لاپەڕەکە هەڵدەگرێت. لە یەک دێت؛ هەر فایلێکی ، وێنە و تایبەتی خۆی دەوێت.
- وا بزانیت
404لە کۆدی .404 Not Foundواتە هیچ فایلێکی لەو نەدۆزییەوە: ناوی فایلەکە، و بپشکنە. لە جیاتی ئەوە500یان پەیامی دەدات. - ناردنی بە
http://ـی سادە. هەر لاپەڕەیەک کە یان تێدا بێت دەبێتhttps://بەکار بهێنێت.
Quick check and exercisesپشکنینی خێرا و ڕاهێنان
Open any website. Press F12 (or right-click and choose Inspect), open the Network tab, and reload the page (F5). Click the first line in the list. Find: (a) the request method, (b) the status code, (c) the Content-Type of the response. Then count how many requests the page needed in total.
هەر بکەرەوە. F12 دابگرە (یان کرتەی ڕاست بکە و Inspect هەڵبژێرە)، تابی Network بکەرەوە و لاپەڕەکە نوێ بکەرەوە (F5). کرتە لە یەکەم دێڕی لیستەکە بکە. ئەمانە بدۆزەرەوە: (أ) ، (ب) ، (ج) Content-Typeـی . پاشان بژمێرە لاپەڕەکە بە گشتی پێویستی بە چەند بوو.
Show answerوەڵامەکە پیشان بدە
For a normal page you will see: (a) method GET, (b) status 200 (sometimes 301 or 304 if the page was moved or is already saved in the browser), (c) text/html; charset=UTF-8 or similar. The list usually has many lines, often dozens: one request for the HTML and one for every CSS file, picture, font and script. This is the "separate requests" step of the page load.
بۆ لاپەڕەیەکی ئاسایی دەبینیت: (أ) GET، (ب) دۆخی 200 (هەندێک جار 301 یان 304 ئەگەر لاپەڕەکە گوازرابێتەوە یان پێشتر لە هەڵگیرابێت)، (ج) text/html; charset=UTF-8 یان شتێکی هاوشێوە. لیستەکە زۆرجار چەندین دێڕی تێدایە، زۆرجار دەیان: بۆ و یەکێک بۆ هەر فایلێکی ، وێنە، فۆنت و . ئەمە هەنگاوی «»ی کردنەوەی لاپەڕەیە.
These steps of the operational trail are mixed up. Put them in the right order: (a) Process PHP; (b) Return HTML; (c) the browser sends a request; (d) Apache finds hello.php; (e) the browser draws the page; (f) PHP reads data from the database.
ئەم هەنگاوانەی ڕێچکەی کارکردن تێکەڵ بوون. بە دروستی ڕێکیان بخە: (أ) جێبەجێکردنی ؛ (ب) ناردنەوەی ؛ (ج) دەنێرێت؛ (د) hello.php دەدۆزێتەوە؛ (هـ) لاپەڕەکە دەکێشێت؛ (و) دراوە لە دەخوێنێتەوە.
Show answerوەڵامەکە پیشان بدە
(c) → (d) → (a) → (f) → (b) → (e). The database step (f) happens while PHP is processing, and only if the page needs data.
(ج) ← (د) ← (أ) ← (و) ← (ب) ← (هـ). هەنگاوی (و) لە کاتێکدا ڕوودەدات کە کار دەکات و تەنها ئەگەر لاپەڕەکە پێویستی بە دراوە بێت.
Rezan saves this file as htdocs/today.php and opens http://localhost/today.php. Write exactly what the server sends to the browser, and what Rezan sees on the screen.
ڕێزان ئەم فایلە وەک htdocs/today.php پاشەکەوت دەکات و http://localhost/today.php دەکاتەوە. بە وردی بنووسە چی دەنێرێت بۆ و ڕێزان چی لەسەر شاشەکە دەبینێت.
<h2>Price list</h2>
<?php
$price = 500;
echo "<p>Tea: $price dinars</p>\n";
echo "<p>2 teas: " . (2 * $price) . " dinars</p>\n";
?>Show answerوەڵامەکە پیشان بدە
<h2>Price list</h2>
<p>Tea: 500 dinars</p>
<p>2 teas: 1000 dinars</p>Price list Tea: 500 dinars 2 teas: 1000 dinars
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<h2>Price list</h2>
<p>Tea: 500 dinars</p>
<p>2 teas: 1000 dinars</p>The browser never receives $price, echo or the calculation 2 * $price: the server has already replaced them with their results.
هەرگیز $price، echo یان هەژمارکردنی 2 * $price وەرناگرێت: پێشتر ئەنجامەکانیانی لە جێیان داناوە.
Shilan adds three products to the shopping cart of an online shop, opens five other pages, and the cart still shows three products. HTTP is stateless, so how does the shop remember her cart?
شیلان سێ کاڵا دەخاتە سەبەتەی کڕینی دوکانێکی ئۆنلاین، پێنج لاپەڕەی تر دەکاتەوە و سەبەتەکە هێشتا سێ کاڵا پیشان دەدات. ، کەواتە دوکانەکە چۆن سەبەتەکەی لە بیر دەمێنێت؟
Show answerوەڵامەکە پیشان بدە
Not with HTTP itself. The shop stores the cart in a session on the server (or in a cookie in her browser). Her browser sends a cookie with a session ID in every request, so the server can find her cart each time.
بە خودی نا. دوکانەکە سەبەتەکە لە لەسەر هەڵدەگرێت (یان لە لە ). لە هەموو دەنێرێت کە تێدایە، بۆیە هەموو جارێک دەتوانێت سەبەتەکەی بدۆزێتەوە.
Summary and reviewکورتە و پێداچوونەوە
- HTTP (HyperText Transfer Protocol) is the language browsers and servers use to ask for and send pages. HTTPS is the same, protected with encryption.
- The client sends a request (method, path, headers); the server sends one response (status code, headers, body).
- PHP is server-side: the browser asks for a
.phppage, the server runs the PHP code, and only HTML comes back. - The operational trail: request → Apache finds the page → PHP processes it (maybe with a database) → HTML is returned → the browser draws it.
- After the HTML arrives, the browser builds the page, sends a separate request for each CSS file, picture and script, and finally runs the JavaScript.
- HTTP is stateless: each request is independent. Websites remember users with cookies (on the client) and sessions (on the server).
- (HyperText Transfer Protocol) ئەو زمانەیە کە و بۆ داواکردن و ناردنی لاپەڕەکان بەکاری دەهێنن. هەمان شتە، بە پارێزراو.
- دەنێرێت (، ، )؛ یەک دەنێرێتەوە (، سەردێڕەکان، لاشە).
- : داوای لاپەڕەیەکی
.phpدەکات، کۆدی جێبەجێ دەکات و تەنها دەگەڕێتەوە. - ڕێچکەی کارکردن: ← لاپەڕەکە دەدۆزێتەوە ← کاری لەسەر دەکات (لەوانەیە لەگەڵ ) ← دەنێردرێتەوە ← دەیکێشێت.
- دوای گەیشتنی ، لاپەڕەکە دروست دەکات، بۆ هەر فایلێکی ، وێنە و جیا دەنێرێت و لە کۆتاییدا جێبەجێ دەکات.
- : هەر سەربەخۆیە. بە (لە لای ) و (لەسەر ) بەکارهێنەران دەناسنەوە.
What are the client and the server in HTTP?ڕاژەخواز و ڕاژەکار لە HTTPـدا چین؟
The client (usually a web browser) sends requests; the server answers each request with one response.
(بە زۆری ) دەنێرێت؛ بە یەک هەر دەداتەوە.
Name the three main parts of an HTTP response.ناوی سێ بەشە سەرەکییەکەی وەڵامێکی HTTP بهێنە.
The status line (with the status code), the headers, and the body.
دێڕی دۆخ (لەگەڵ )، و لاشە.
Why can visitors never see your PHP code?بۆچی سەردانکەران هەرگیز کۆدی PHPـەکەت نابینن؟
Because the server runs it and sends only its HTML output. View Page Source shows that HTML, not the PHP.
چونکە جێبەجێی دەکات و تەنها دەنێرێت. View Page Source ئەو پیشان دەدات، نەک .
What does Apache do differently with about.html and hello.php?Apache چ جیاوازییەک لە نێوان about.html و hello.phpدا دەکات؟
It sends about.html exactly as it is. It gives hello.php to the PHP interpreter first and sends only the HTML output.
about.html هەروەک خۆی دەنێرێت. hello.php سەرەتا دەدات بە و تەنها دەنێرێت.
When does the server send an error response?ڕاژەکارەکە کەی وەڵامێکی هەڵە دەنێرێت؟
When it cannot find the page (404) or something else goes wrong (for example 500 for an error on the server).
کاتێک لاپەڕەکە نەدۆزێتەوە (404) یان شتێکی تر نادروست بڕوات (بۆ نموونە 500 بۆ لەسەر ).
Give one advantage and one disadvantage of HTTP being stateless.سوودێک و زیانێکی بێدۆخ بوونی HTTP بڵێ.
Advantage: simpler servers and greater scalability. Disadvantage: extra work (cookies, sessions) to remember users across requests.
سوود: و فراوانبوونی زیاتر. زیان: کاری زیادە (، ) بۆ ناسینەوەی بەکارهێنەران لە نێوان .
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
A clear tour of HTTP: why it is stateless, what HTTPS adds, methods like GET and POST, headers, and status codes.
گەشتێکی ڕوون بەناو : بۆچی ، چی زیاد دەکات، وەک GET و POST، و .
Watch 1:25–11:36, HTTP, stateless, HTTPS, methods, headers, status codes
لە 1:25 تا 11:36 سەیر بکە: بۆچی ، ، ، و .
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Static and Dynamic Websites and Website Typesلاپەڕەتۆڕە نەگۆڕەکان، لاپەڕەتۆڕە داینامیکەکان و جۆرەکانی تۆڕگە
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.