ColdFusion Home

General / Quick Scripts

Escaping #

To escape the # symbol in ColdFusion just use it twice : ##
Variables in ColdFusion are not case sensitive. #cgi# = #CGI#.

Site you are runnign in

This pieace of code will show what SITE you are in for shared hosting ( the root directory ).

#server.coldfusion.rootdir#
Example = You are in : C:\ColdFusion11\cfusion

What OS

This will show the operating systems name.

#server.os.name#
Eample = Your server is running : Windows Server 2012

IP

This will show you the Address of the computer conneting to your site.

#CGI.REMOTE_ADDR#
Eample = Your IP is : 54.198.2.110

Host

This will display the Host name or Host / IP address of the server that you are conneted to.

#cgi.HTTP_HOST#
Eample = The server site IP / HOST is : wcc.web-project.name

Page name

This will display the name of the page you are currently on.

#listlast(cgi.script_name,"/")#
Eample = The current page is : general-scripts.cfm

Directory path

This will display the current directory and path you are in, 2 different methods

#ExpandPath('.')#
Eample = The current Directory path is : D:\Inetpub\web-project\ColdFusion

#GetDirectoryFromPath(GetTemplatePath())#
Eample = The current Directory path is : D:\Inetpub\web-project\ColdFusion\

Date

Here we are using the ( NULL | short | medium | long | full ) format.
Referance

#dateFormat(now())#
Output = 18-Nov-17

#dateFormat(now(), "short")#
Output = 11/18/17

#dateFormat(now(), "medium")#
Output = Nov 18, 2017

#dateFormat(now(), "long")#
Output = November 18, 2017

#dateFormat(now(), "full")#
Output = Saturday, November 18, 2017

#dateFormat(now(), "yyyy-mmmm-dd")#
Output = 2017-November-18

Time

Here we are using the ( NULL | short | medium | long | full ) format.
Referance

#timeFormat(now())#
Output = 04:12 PM

#timeFormat(now(), "short")#
Output = 4:12 PM

#timeFormat(now(), "medium")#
Output = 4:12:29 PM

#timeFormat(now(), "long")#
Output = 4:12:29 PM MST

#timeFormat(now(), "full")#
Output = 4:12:29 PM MST


Here I am goign to specify the time

#timeFormat(now(), "hh:mm:ss")#
Output = 04:12:29

#timeFormat(now(), "hh:mm:ss t")#
Output = 04:12:29 P

#timeFormat(now(), "hh:mm:ss tt")#
Output = 04:12:29 PM

#timeFormat(now(), "HH:mm:ss")#
Output = 16:12:29

cf mail example

Here you can put the velow in to a .cfm file and upload to an account to check and make sure that the mail function is working properly.

<cfmail
server = "mailx2.newtekwebhosting.com"
to="test@web-project.name"
from="test@web-project.name"
subject="Testing the cfmail Tag"
username = "test@web-project.name"
password = "PASWORD"
wraptext = 70
type="html">
<html>
<body>
<p>Hello, This is an email sent from the cfmail tag. </p>
<cfoutput>
Sent from : http://#cgi.server_name##cgi.script_name#?#cgi.query_string#
<br />on <br/>#datatime#
<hr/><cfdump var="#CGI#" />
</cfoutput>
</body>
</html>
</cfmail>


This Page loaded
The cfmail tag has been processed
<cfset datatime = CREATEODBCDATETIME( Now() ) />
<cfoutput>#datatime#</cfoutput>