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?
get cookie content from javascript ?
Javascript
var c = document.cookie
console.log(c)
PHP
$_COOKIE[$cookie_name]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.