J
J
John2015-11-30 22:10:15
PHP
John, 2015-11-30 22:10:15

How to write cookies correctly?

I write cookies like this:

$lpg = $_GET['utm'];
setcookie('lpg', $lpg, time()+60*60*24*60); //кука 60 дней

Now the question is:
How can I add more text to the cookie?
for example, in our cookies: lpg = cookies1
we again go to site.com/?utm=cookies2
and we should also write the cookies2 cookie
, it turns out we should have cookies1_cookies2 in the lpg cookie, that is,
we edit the old cookie and write a new one, lpg = cookies1_cookies2
did like this:
<?php
$lpg = $_GET['utm'];
if(isset($_COOKIE['lpg']) && $_COOKIE['lpg'] != '') { // Если не пустая...
    $c = $_COOKIE['lpg']; // ...получить куку...
    setcookie('lpg', "$c_$lpg", time()+60*60*24*60); // ...и дописать "_$lpg"
} else { // Если пустая...
    setcookie('lpg', $lpg, time()+60*60*24*60); // ...просто заполнить "$lpg"
}

?>

but for some reason it just updates the cookie =((

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Matrozov, 2015-11-30
@john_notebook

Add - no way. You can read the old value and add what you need there, saving it again with the same name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question