I have a cookie and need to read it with JQuery or just javascript if JQuery alone is not possible.
Then I need to pass the value of that Cookie to a PHP variable
Can this be done?
UPDATE: I need everything to happen in the same page.
- Javascript reads the already existing cookie.
- $somePHPvariable = MyJavascriptCookieValue;
I need to use Javascript to read this cookie because I am using a wordpress cookie created in function.php and php cannot read the cookie when it’s create but after the next reload of the page, which is no good to me.
In PHP you can directly get the value of the cookie with
$_COOKIE['variable_name']…If you really want to get the value of the cookie in JavaScript then here is one of a few different plugins to help read/write cookies with jQuery: https://github.com/carhartl/jquery-cookie
You can then use AJAX to send the cookie information to your PHP script:
This will send the cookie as the GET variable
cookie. You will be able to access it via PHP like this:$_GET['cookie'].