Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript cookies vs php cookies

Tags:

javascript

php

Is there a difference between javascript cookies and php cookies?

like image 705
pundit Avatar asked Apr 01 '10 17:04

pundit


People also ask

Are JS and PHP cookies the same?

There is no difference between cookies stored through js and ones stored through php, they are the same. Thanks. There is no difference between cookies stored through js and ones stored through php, they are the same.

What is a PHP cookie?

A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Can you use cookies with JavaScript?

JavaScript can create, read, and delete cookies with the document.cookie property. With JavaScript, a cookie can be created like this: document.cookie = "username=John Doe"; You can also add an expiry date (in UTC time).

Which is better session or cookie in PHP?

Both of them accomplish much the same thing. The main difference between cookies and sessions is that information stored in a cookie is stored on the visitor's browser, and information stored in a session is not—it is stored at the web server. This difference determines what each is best suited for.


2 Answers

HTTP Cookies are not a feature of PHP, nor a feature of Javascript : those are just programming languages that allow a developper to manipulate them.


The biggest difference between JS and PHP is that :
  • Javascript runs on the client side
  • PHP runs on the server side

But cookies are still the same : they are defined as a standard -- see RFC 2965.


Still, note that modern browsers implement cookies that are not accessible from Javascript *(see the `httponly` option of [`setcookie`][3])* -- which means that, depending on the browser, and the way a cookie was set, it might not be accessible from Javascript.

This is a security measure -- and is not a difference between "js cookies" and "php cookies" : it's just a property of some cookies.

like image 160
Pascal MARTIN Avatar answered Sep 20 '22 00:09

Pascal MARTIN


No, cookies are defined by an RFC spec.

like image 33
ryeguy Avatar answered Sep 19 '22 00:09

ryeguy