Skip to content
PHP Logo

What is the difference between handling cookies in PHP 4.xx and PHP 5.0?

In PHP 4.xx, cookies were handled using the setcookie() function with a different syntax compared to PHP 5.0. In PHP 5.0, the setcookie() function had a new parameter for setting the cookie's expiration time. To handle cookies in PHP 5.0, you need to adjust the syntax of the setcookie() function to include the expiration time parameter.

php
// PHP 4.xx syntax for setting a cookie
setcookie("cookie_name", "cookie_value", time() + 3600);

// PHP 5.0 syntax for setting a cookie with expiration time
setcookie("cookie_name", "cookie_value", time() + 3600, "/");