Skip to content

System Variables#


System variables in Miva Merchant provide powerful built-in functionality by giving developers access to a wide range of pre-initialized data. These variables, referenced using the s. prefix, are initialized at the start of script execution and are invaluable for handling HTTP headers, CGI environment variables, and Miva-specific system data.

This guide explores the types of system variables, how to use them, and practical examples to integrate them into your templates.


Types of System Variables#

Dynamic Variables#

Dynamic system variables are reset each time they are accessed in an expression. They are commonly used in time-related functions where values need to be updated dynamically.

Example:

<mvt:assign name="g.current_time" value="s.dyn_time_t" />

Static Variables#

Static system variables are initialized once at the start of script execution and retain their value throughout. These are ideal for stable data like the client’s IP address or HTTP headers.

Example:

<mvt:assign name="g.client_ip" value="s.remote_addr" />


Common System Variables#

s.remote_addr#

Retrieves the IP address of the client making the request.

Example:

<p>Client IP: <mvt:eval expr="s.remote_addr" /></p>

s.http_referer#

Returns the referring page’s URL.

Example:

<mvt:assign name="g.referer" value="s.http_referer" />
<p>Referred From: &mvt:global:referer;</p>

s.http_user_agent#

Provides information about the client’s browser and operating system.

Example:

<p>User Agent: <mvt:eval expr="s.http_user_agent" /></p>


Using System Variables in Templates#

System variables cannot be directly output to the page but can be used with <mvt:eval> or assigned to other variables for further processing.

Example: Conditional Logic#

<mvt:if expr="s.remote_addr EQ '127.0.0.1'">
    <p>Welcome, Developer!</p>
<mvt:else>
    <p>Welcome, Visitor!</p>
</mvt:if>

Advanced Usage#

Example: Logging System Variables#

System variables can be logged for debugging or analytics.

<mvt:assign name="g.log_message" value="'Client IP: ' $ s.remote_addr $ ' | Referer: ' $ s.http_referer" />
<mvt:do file="g.module_library_utilities" name="l.log_result" value="WriteLog(g.log_message)" />

Example: Using System Variables with Custom Functions#

System variables can be passed to Miva functions for further processing.

<mvt:assign name="g.is_internal" value="substring(s.remote_addr, 1, 7) EQ '192.168'" />
<mvt:if expr="g.is_internal">
    <p>You are accessing this site internally.</p>
<mvt:else>
    <p>You are accessing this site externally.</p>
</mvt:if>

Best Practices#

  1. Understand Variable Scope:

    • Use system variables for stable or frequently accessed data like IP addresses or HTTP headers.
  2. Combine with Conditional Logic:

    • Leverage system variables for personalized or context-aware content delivery.
  3. Log Data for Debugging:

    • Use system variables to track and debug client requests effectively.
  4. Avoid Overuse:

    • Only use system variables when necessary to keep templates optimized and maintainable.

Summary#

System variables provide a robust foundation for handling environment data, enhancing template logic, and delivering personalized experiences in Miva Merchant. By understanding their types and capabilities, developers can harness these variables to create more dynamic and efficient templates.

Continue to Time Functions → to explore time-based operations and dynamic timestamps.