Showing results for 
Search instead for 
Did you mean: 

HowTo: TrafficScript Syntax

TrafficScript is a simple, command-based language. A command is called a 'statement', and each statement is terminated with a ';'. Comments begin with a '#' symbol, and finish at the end of the line:


# Store the value '2' in the variable named $a  
$a = 2;  
# call the 'connection.close' function  


Variables are indicated by the '$' symbol. There is no typing in TrafficScript, and you do not need to pre-declare a variable before you use it. Variables are not persistent - they go out of scope when a rule completes.


You can use variables in expressions to calculate new values (numbers and strings). Common mathematical, comparison and boolean operators are available, and '.' is used to concatenate strings.


# Set the value of $a to 1.75  
$a = 1 + 1/2 + 0.25;  
# create a new string with the '.' operator  
$fullname = $firstname . " " . $lastname;  


Functions are called using the normal bracket-and-argument-list syntax, and many functions can take different numbers of arguments. Function names often contain two or three parts, separated by '.'; this conveniently groups functions into different families.


$path = http.getPath();  
$cookie = http.getCookie( "ASPSESSIONID" );  
$browser = http.getHeader( "User-Agent" ); 


TrafficScript also provides data structures in the form of arrays and hashes. Arrays and hashes allow you to store multiple values in one TrafficScript structure. For more information, see the HowTo: TrafficScript Arrays and Hashes article.


Read more


Version history
Revision #:
5 of 5
Last update:
‎08-20-2019 04:16:AM
Updated by:
Labels (1)