Whatever message this page gives is out now! Go check it out!

CSRFGenerateToken

Last update:
May 18, 2026

Description

Provides a random token and stores it in the session. You can also provide a specific key to store in the session.

Returns

Token

Category

Display and formatting functions

Syntax

CSRFGenerateToken([key] [,forceNew])

See also

History

ColdFusion 10: Added this function.

Parameters

Parameter
Required\Optional
Description
key
optional
A random token is generated based on the key provided. This key is stored in the session.
forceNew
optional
If set to true, a new token is generated every time the method is called. If false, in case a token exists for the key, the same key is returned.

Usage

Use this function to create a random token and store it in the session.

Example

<cfset csrfToken=CSRFGenerateToken() /> 
<cfform method="post" action="sayHello.cfm"> 
<cfinput name="userName" type="text" > 
<cfinput name="token" value="#csrfToken#" type="hidden" > 
<cfinput name="submit" value="Say Hello!!" type="submit" > 
</cfform>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page