• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Step 2. Using Variables > Example 2.1: Using CGI Variables

Example 2.1: Using CGI Variables

In this example, we will create a ColdFusion template to display some commonly used CGI variables.

1.
Open your editor and type the code shown in Listing 2.1, or you can open the CGIVariables.cfm file from the CompletedFiles\Examples\Step02 folder.
Listing 2.1. Commonly Used CGI Variables

<!---
File:        CGIVariables.cfm 
Description: Displays some common CGI variables 
Author: 
Created: 
---> 

<HTML> 
<HEAD> 
      <TITLE>Common CGI Variables</TITLE> 
</HEAD> 

<BODY> 
<CFOUTPUT> 
<!--- display some commonly used CGI variables ---> 
<B>User's Browser Type:</B> HTTP_USER_AGENT = #CGI.HTTP_USER_AGENT#<BR> 
<B>User's IP Address:</B> REMOTE_ADDR = #CGI.REMOTE_ADDR#<BR> 
<B>Referring Page:</B> HTTP_REFERER = #CGI.HTTP_REFERER#<BR> 
<B>Server's Name:</B> SERVER_NAME=#CGI.SERVER_NAME#<BR> 
<B>Server's Port:</B> SERVER_NAME=#CGI.SERVER_PORT#<BR> 
</CFOUTPUT> 

</BODY> 
</HTML>



2.
Save this file into your Examples\Step02 directory as CGIVariables.cfm.

3.
Use a URL to browse to the page. For example, http://localhost/Examples/Step02/CGIVariables.cfm.

4.
You should see something similar to the page displayed in Figure 2.2.

Figure 2.2. CGIVariables.cfm browser display.


5.
To see HTTP_REFER information, set up a hyperlink to CGIVariables.cfm on another page and use the link to jump to CGIVariables.cfm.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint