CI cookie storage array

Source: Internet
Author: User
 

  

1 # CI cookie because it cannot store arrays, all must be serialized and stored in the array 2 3 # define Array 4 $ cookie_array = array (5 'shop _ id' => $ GID, 6 'shop _ name' => $ shop_obj [0] ['main _ title'], 7 'shop _ IMG '=> $ shop_obj [0] ['goods _ IMG'], 8 'shop _ price' => $ shop_obj [0] ['price'], 9 'shop _ old_price '=> $ shop_obj [0] ['old _ price'] 10 ); 11 # The reason for Array serialization is that the cookie can only store strings 12 $ cookie_data = serialize ($ cookie_array); 13 # store cookie14 setcookie ("cookie_data", $ cookie_data, time () + 3600 ); 15 # retrieve the cookie and serialize 16 $ data_info = unserialize ($ _ cookie ['cookie _ data']); 17 var_dump ($ data_info ); 18 19 20 21 # After serialization 22 A: 5: {s: 7: "shop_id"; s: 1: "4"; s: 9: "shop_name"; s: 37: "[4 stores general] butterfly flower Cafe"; s: 8: "shop_img"; s: 18: "14084523762428.jpg"; s: 10:" shop_price "; s: 4: "79.0"; s: 14: "shop_old_price"; s: 5: "214.0 ";} 23 24 #25 array26 (27 [shop_id] => 428 [shop_name] => [4 store General] butterfly flower cafe 29 [shop_img] => 14084523762428.jpg 30 [shop_price] => 79.031 [shop_old_price] => 214.032)

 

CI cookie storage array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.