Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: get set_cookie how to? (Read 1640 times) previous topic - next topic

get set_cookie how to?

Hello
OK Help ,
This work outside phprad :
<?php 
$cookie = "user";
$value = "value";
setcookie($cookie, $value, time() + (86400), "/");
?>
and according helpers this should work in phprad:
file .../product/list.php
<?php
$cookie = "user";
$value = "value";
set_cookie($cookie,$value,$days=1);
print_r($_COOKIE);
?>
I  have try also  set_cookie($cookie,$value,1,'/'); header("Location: print_link('product')"); .... and other similar....
but I get this:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\stock\helpers\Html.php:91) in C:\xampp\htdocs\stock\helpers\Functions.php on line 587

so what I'm missing? how to set get cookie?

Re: get set_cookie how to?

Reply #1
@dobsun‍ please go through the phprad View Helper Functions for functions you can use. Your issue is this header("Location: print_link('product')") PHPrad already has a function to hand redirect, redirect_to_action($action_name=null) and redirect($url) and make sure to add exit after the redirect.
Code: [Select]
set_cookie("user",$value,1);
redirect("/product");
exit;
in the product page
Code: [Select]
$userDetails = get_cookie("user");

Re: get set_cookie how to?

Reply #2
@willvin
Array issue
Thank you very much for hint! it work perfect for single string! But array, not
I set array like this
 set_cookie("cart[$product_id]",$quantity,$expire);
I found how to get single value
$c_arr=get_cookie ('cart');
echo ($c_arr)[$product_id];

Clear Not working for array /I have try many different combinations.../
clear_cookie('cart'); - not working
clear_cookie('$c_arr'); -not
clear_cookie('cart')[$product_id]; - works for single !

I'll come back, if I find how to clear !

 

Re: get set_cookie how to?

Reply #3
resolved:
$c_arr=get_cookie ('cart');
   if (isset($c_arr)) {
    foreach ($c_arr as $name => $value) {
        clear_cookie ("cart[".$name."]");
    }