Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get/Read Javascript cookie with PHP

I have a theoretical question..

I know that you can get/read a PHP cookie with javascript by using: document.cookie

Is there a similar way to do this in PHP?

Can PHP get/read a cookie that is created i JavaScript? If yes, then how can you do that?

like image 523
Spoofy Avatar asked Mar 14 '14 00:03

Spoofy


People also ask

Can PHP read JavaScript cookie?

cookie php cannot assess the cookie, php can only assess cookie set by document.

How can I see cookies in PHP?

Accessing Cookies with PHP Simplest way is to use either $_COOKIE or $HTTP_COOKIE_VARS variables. Following example will access all the cookies set in above example. You can use isset() function to check if a cookie is set or not.

What is cookie read cookie in PHP?

A cookie is often used to identify a user. 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.

What is $_ cookies?

A cookie is a piece of data from a website that is stored within a web browser that the website can retrieve at a later time. Cookies are used to tell the server that users have returned to a particular website.


1 Answers

You can use $_COOKIE, the superglobal. Just reference it like you would any array, where $_COOKIE['key_name'] is the cookie you want to access.

See the PHP API documentation.

like image 122
jacobroufa Avatar answered Oct 19 '22 03:10

jacobroufa