Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to create and print array of cookies with setcookie in PHP

3 Answers

0 votes
/*
bool setcookie ( string $name [, string $value = "" [, int $expire = 0 
                                                    [, string $path = "" 
                                                    [, string $domain = "" 
                                                    [, bool $secure = false 
                                                    [, bool $httponly = false ]]]]]] )

*/
 
// expire at the end of the session, when the browser closes
setcookie("cookie[one]", "cookie_one");
setcookie("cookie[two]", "cookie_two");
setcookie("cookie[three]", "cookie_three");
?>
<html>
<body>
<?php

if (isset($_COOKIE['cookie'])) {
    foreach ($_COOKIE['cookie'] as $name => $value) 
        echo "$name : $value <br />";
}
?>
</body>
</html> 
<?php
      
/*
run:
  
three : cookie_three 
two : cookie_two 
one : cookie_one 
  
*/

?>

 



answered Dec 20, 2015 by avibootz
0 votes
<?php
/*
bool setcookie ( string $name [, string $value = "" [, int $expire = 0 
                                                    [, string $path = "" 
                                                    [, string $domain = "" 
                                                    [, bool $secure = false 
                                                    [, bool $httponly = false ]]]]]] )

*/
 
// expire at the end of the session, when the browser closes
setcookie("cookie[one]", "cookie_one");
setcookie("cookie[two]", "cookie_two");
setcookie("cookie[three]", "cookie_three");
?>
<html>
<body>
<?php

echo '<pre>' . print_r($_COOKIE, 1) . "</pre>";

?>
</body>
</html> 
<?php
      
/*
run:
  
Array
(
    [user_name] => Erin Baron
    [cookie] => Array
        (
            [three] => cookie_three
            [two] => cookie_two
            [one] => cookie_one
        )

)

  
*/

?>

 



answered Dec 20, 2015 by avibootz
0 votes
<?php
/*
bool setcookie ( string $name [, string $value = "" [, int $expire = 0 
                                                    [, string $path = "" 
                                                    [, string $domain = "" 
                                                    [, bool $secure = false 
                                                    [, bool $httponly = false ]]]]]] )

*/
 
// expire at the end of the session, when the browser closes
setcookie("cookie[one]", "cookie_one");
setcookie("cookie[two]", "cookie_two");
setcookie("cookie[three]", "cookie_three");
?>
<html>
<body>
<?php

echo $_COOKIE['cookie']['one'] . "<br />";
echo $_COOKIE['cookie']['two'] . "<br />";
echo $_COOKIE['cookie']['three'] . "<br />";

?>
</body>
</html> 
<?php
      
/*
run:
  
cookie_one
cookie_two
cookie_three
  
*/

?>

 



answered Dec 20, 2015 by avibootz

Related questions

2 answers 274 views
1 answer 533 views
1 answer 167 views
1 answer 197 views
3 answers 263 views
1 answer 222 views
...