Skip to content
PHP Logo

What is the difference between accessing a cookie using $_COOKIE and a normal variable in PHP?

When accessing a cookie using $_COOKIE in PHP, you are retrieving the value of a specific cookie that has been set in the browser. This method allows you to access cookies that have been sent with the HTTP request. On the other hand, when using a normal variable in PHP, you are storing and retrieving values within the server-side code without involving cookies.

php
// Accessing a cookie using $_COOKIE
$cookieValue = $_COOKIE['cookie_name'];

// Using a normal variable in PHP
$normalVariable = "Hello, World!";