Get value from cookie using json_decode
P粉235202573
P粉235202573 2024-02-26 21:39:51
0
1
375

I'm setting a cookie and it works fine, but for some reason I can't retrieve the cookie's value. I can see that the cookie is set in the browser developer tools, but when I try to print_r it shows up as empty.

This is where I see the cookie value in the developer tools.

This is where I'm trying to get the value which currently doesn't work:

$additionalData = json_decode($_COOKIE['antennasNow'], true);
echo '<pre>';
print_r($additionalData);
echo '</pre>';

This is where I set the cookie, in case it helps:

setcookie('antennasNow', json_encode($cookieValue), time() 3600);

This is how I set the cookie value, in case it helps:

$cookieValue = array(
        'base_Sku' => $base_Sku,
        'vhf_UHF_Type' => $vhf_UHF_Type,
        'ptc_Type' => $ptc_Type,
        'type_700_800_900' => $type_700_800_900,
        'band' => $band,
        'polarization' => $polarization,
        'gain_Sku' => $gain_Sku,
        'exposed_Dipole_Az_Pattern' => $exposed_Dipole_Az_Pattern,
        'collinear_Az_Pattern' => $collinear_Az_Pattern,
        'panel_Az_Pattern' => $panel_Az_Pattern,
        'dual_Input' => $dual_Input,
        'narrowband_Connector' => $narrowband_Connector,
        'beamtilt' => $beamtilt,
        'null_Fill' => $null_Fill,
        'heavy_Duty' => $heavy_Duty,
        'invert_Mount' => $invert_Mount,
    );

I followed these tips/steps from other threads:

PHP Decode JSON from cookie

json_decode_to_array

Storing PHP arrays in cookies

P粉235202573
P粉235202573

reply all(1)
P粉835428659

Just replace your debug code with this -

$additionalData = json_decode(stripslashes($_COOKIE['antennasNow']), true);
    echo '
';
    print_r($additionalData);
    echo '
';
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!