R
R
Regina Khairullina2019-03-18 10:21:36
PHP
Regina Khairullina, 2019-03-18 10:21:36

How to set cookie in js and pass cookie value to php code?

I'm trying to determine the city of the site visitor by ip.
1) The Yandex service determines the city and an inscription appears in the menu, for example: Your city: Ufa
2) You need to take the cookie value from js and display it in php code. The catch is that I'm just learning js and it's still not entirely clear to me how to transfer from js to php. I realized that you can get and fast. In this variant I try to transfer a getom. But the het is empty. How to write cookies to see them in <?php echo $_GET['cook']; ?>????


window.onload = function () {
jQuery("#user-city").text(ymaps.geolocation.city);
jQuery("#user-region").text(ymaps.geolocation.region);
jQuery("#user-country").text(ymaps.geolocation.country);
var city = ymaps.geolocation.city;
var cook = document.cookie = name + "=" + city; // write city to cookie
}

I'm stuck at this point, I can't move forward, please tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TCloud, 2019-03-18
@OTCloud

PHP can handle cookies on its own. So you don't need to pass anything from js.
Working with cookies in PHP
php.net/manual/en/features.cookies.php
If you receive cookies via $_GET, then you can send them via ajax.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question