PHP Kukilər | $_COOKIE | cookies in PHP

Описание к видео PHP Kukilər | $_COOKIE | cookies in PHP

Kuki veb saytdan göndərilən və istifadəçinin brauzerində saxlanılan kiçik həcmli məlumatdır. İstifadəçi sayta yenidən daxil olduqda, brauzer həmin kukini serverə göndərir və bununla da server istifadəçini “tanımış” olur. Kukilər əsasən aşağıdakı məqsədlər üçün istifadə olunur:
• İstifadəçi sessiyalarını izləmək
• İstifadəçi seçimlərini saxlamaq (məsələn, dil seçimi)
• Alış-veriş səbətini saxlamaq
• Kontenti fərdiləşdirmək

PHP-də kuki yaratmaq (setcookie)
setcookie(name, value, expire, path, domain, secure, httponly);

Parametrlər:
1. name: Kukinin adı (sətir tipli).
2. value: Kukidə saxlanılacaq dəyər (adətən sətir).
3. expire: Kukinin vaxt limiti (müddəti). UNIX zaman möhürüdür (timestamp)
4. path: Serverdə kukinin mövcud olacağı yol (adətən "/" olur).
5. domain: Kukinin etibarlı olduğu (sub)domen (adətən cari domen).
6. secure: true olduqda, kuki yalnız HTTPS bağlantısı ilə göndərilir.
7. httponly: true olduqda, kukiyə yalnız server tərəfindən müraciət etmək olur, JavaScript-lə müraciət etmək mümkün olmur (XSS hücumlarının qarşısını almağa kömək edir).

Vacibdir: Kuki başlıqları (header) bütün HTML çıxışından əvvəl göndərilməlidir. Yəni echo, print və ya hər hansı HTML kodundan əvvəl setcookie() çağırmaq lazımdır.

=====

A cookie is a small piece of data sent from a website and stored on the user’s computer by the user’s web browser. When the user revisits the website, the browser sends the cookie back to the server, allowing the server to recognize and remember data about the user. Common use cases include:
• Tracking user sessions
• Storing user preferences
• Keeping items in a shopping cart
• Personalizing content

Setting a cookie in PHP
setcookie(name, value, expire, path, domain, secure, httponly);

Where the parameters are:
1. name: The cookie’s name (a string).
2. value: The value you want to store in the cookie (usually a string).
3. expire: The time the cookie expires. This is a UNIX timestamp. If set to zero or omitted, the cookie expires at the end of the session (when the browser is closed).
4. path: The path on the server in which the cookie is available (default is "/").
5. domain: The (sub)domain for which the cookie is valid (default is the current domain).
6. secure: If true, the cookie will only be sent over secure HTTPS connections.
7. httponly: If true, the cookie cannot be accessed through client-side JavaScript (helps mitigate XSS attacks).

Important: Cookies must be sent before any HTML output. This means setcookie() should be called before any echo, print, or HTML tags.

#kody_az #kodyaz #php #phpcode #laravel #phpprogramming #viral #viralcode #viralvideo #random #code #coder #azerbaycan #azerbaijan #baku #baki #programming #programmer #codes #hazırlıq #hazirliq #kurs #kurslar #course #courses #online #onlinecourses #test #quiz

Комментарии

Информация по комментариям в разработке