1

I'm working on a project which runs a PHP document on localhost. The PHP accepts and saves-as-cookie some user input.

Then it's supposed to execute a javascript script which uses the data in the cookie to perform a calculation, and return the calculation to the PHP document.

The first part is fine. The application prompts user for input and saves it to a cookie as expected. I check chrome://settings/cookies and see the cookie in locally stored data, Domain: localhost. fine.

In the same directory, I have a file called calculate.js. I know calculate.js is working, and being executed correctly from the PHP, with dummy data. But: How can I save the value of the cookie to a var in calculate.js?

LSerni
  • 55,617
  • 10
  • 65
  • 107
  • Possible duplicate of [How do I create and read a value from cookie?](http://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie) – Qirel May 01 '17 at 09:28
  • Or http://stackoverflow.com/questions/10730362/get-cookie-by-name – Qirel May 01 '17 at 09:28

1 Answers1

2

get cookie content from javascript ?

Javascript

var c = document.cookie
console.log(c)

PHP

$_COOKIE[$cookie_name]
Vin
  • 97
  • 4