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?

2

1 Answer 1

2

get cookie content from javascript ?

Javascript

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

PHP

$_COOKIE[$cookie_name]
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, I'm still not getting it. I mean, the cookie is defined in PHP, and the Javascript is supposed to (let's say) console log it. Is that what you have described?
Why dont't​ you try it? Yes I suppose it is.
php - [Set cookie] -> javascript get it? document.cookie not work?
maybe you can check this, split and get it by name stackoverflow.com/questions/10730362/get-cookie-by-name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.