Skip to content

Cookies#


Cookies play a pivotal role in web development and are extensively utilized across virtually all websites. They serve as small data pieces stored locally by browsers, facilitating various functionalities such as session management and user authentication. While typically limited in size, cookies offer a versatile means of data storage and retrieval. In Miva Merchant, developers can harness the power of cookies through the Template Language (MVT), enabling dynamic and personalized web experiences. This documentation provides comprehensive guidance on leveraging cookies within Miva Merchant’s framework.

Set Cookies#

Developers can establish custom cookies using the miva_output_header function, enabling the inclusion of custom data within cookies.

  • Key Components:
    • Name-Value Pair: Assign a unique name and value to the cookie.
    • Expiration: Specify the cookie’s expiration date and time.
    • Path: Define the accessibility scope of the cookie within the website hierarchy.

Example#

<mvt:assign name="g.output_header" value="miva_output_header('Set-Cookie','mycookie=helloworld; expires=Tue, 24-Jul-2013 00:00:01 GMT; path=/;')" />

Reading Cookies#

Miva Merchant automatically parses cookies, converting them into accessible global variables for seamless retrieval and utilization. Cookies are accessible via global variables, facilitating easy integration into Miva pages.

Example#

&mvte:global:request_cookies:mycookie;

Iterate Through Cookies#

Utilize the miva_struct_members function to convert cookie structures into arrays, enabling iteration through all available cookies. By employing the mvt:foreach loop to iterate through cookie arrays you can extract both cookie names and values.

Example#

  <mvt:assign name="g.cookie_count" value = "miva_struct_members( g.request_cookies, g.cookies)" />
  <mvt:foreach iterator="cookie" array="global:cookies">
      <mvt:assign name="l.settings:cookie_value" value="miva_variable_value('g.request_cookies:' $ l.settings:cookie)" />
      <mvt:if expr="NOT ISNULL l.settings:cookie_value">
          Name: &mvt:cookie;  Value: &mvt:cookie_value; <br>
      </mvt:if>
  </mvt:foreach>

Delete Cookies#

To delete a cookie, set its expiration date to a past timestamp, prompting browsers to remove the cookie automatically.

Example#

<mvt:assign name="g.output_header" value="miva_output_header('Set-Cookie','mycookie=helloworld; expires=Tue, 24-Jul-2999 00:00:01 GMT; path=/;')" />

Summary#

Cookies serve as invaluable tools in web development, facilitating data storage, session management, and user personalization. With Miva Merchant’s robust Template Language, developers can effortlessly manage cookies, empowering them to create dynamic and interactive web experiences. By mastering cookie management techniques within Miva Merchant, developers can enhance website functionality, improve user experiences, and unlock a myriad of customization possibilities.