This is a simple tutorial showing you how to create your own coldfusion code to display an advertisement before a person enters the site. Although, instead of using plain old cookies, we will enhance this using additional parameters.


If you don't know what I am talking about then please view my live example here:
http://www.gamingempires.com/fusion/front.cfm 


We will work our way backwards, first we will start with the content that happens after the advertisement. Let's name this page index.cfm.

<!-- We are using 2 parameter names, stable and kramer, I will explain them as we go on --->
<cfif isdefined("stable") or isdefined("cookie.kramer")>

    <!-- Here you will be able to place your site content --->
    You are on the main page, here you can display your whole site.

    <!--- We are using abort to disable showing the ad and the site at the same time --->
   
<cfabort>
</cfif>


Above is where your ordinary page layout would be. I have set a isdefined parameter to check if stable OR cookie.kramer exists. If they exist, then your ordinary page would be displayed, if it doesn't exist then the advertisement would be displayed, which is the next part.

<!--- We check if cookie.kramer doesn't exist, if it doesn't then we display the ad --->
<cfif not isdefined("cookie.kramer")>

    <!--- Below you place your advertisements --->
    <h1><b>Advertisement would go here</b></h1>
    <br><br>


    <!--- Once you have viewed the advertisement, we want to create a cookie so that the advertisement doesn't appear next time. We name this cookie kramer, with any value. We set the expiration to 14 days so that you see the ads every 14 days. --->
    <cfcookie name="kramer" value="1" expires="14" domain=".yoursitename.com">

    <!--- Below we set the other parameter, this will make us skip the advertisement to view the website. This is also useful if a person has cookies disabled, therefore he/she can skip the ad instead of having to enable his/her cookies --->
    <a href="index.cfm?stable=1">Continue</a>
</cfif>

That is all, we first enter the site page index.cfm, and see an advertisement. Once the advertisement has loaded, it will set a cookie. Below the advertisement we have the word Continue which we can press to go to the main layout (which is the same file, index.cfm). As soon as we press continue the page redirects to index.cfm?stable=1 which is where we place our site content. Once that is done we can return to index.cfm and notice that the advertisement is gone since the cookie was found. Just copy and paste the code below and see how it works! Be sure to save it as index.cfm! 


<cfif isdefined("stable") or isdefined("cookie.kramer")>
    You are on the main page, here you can display your whole site.
    <cfabort>
</cfif>



<cfif not isdefined("cookie.kramer")>
    <cfcookie name="kramer" value="1" expires="14" domain=".yoursitename.com">
    <h1><b>Advertisement would go here</b></h1>
    <br><br>

    <a href="index.cfm?stable=1">Continue</a>
</cfif>

You can find a live example here:

http://www.gamingempires.com/fusion/front.cfm 

Thanks for reading. Until next time, Matt Wegrzyn.

About This Tutorial
Author: Matt Wegrzyn
Skill Level: Beginner 
 
 
 
Platforms Tested: CFMX
Total Views: 31,332
Submission Date: August 29, 2004
Last Update Date: June 05, 2009
All Tutorials By This Autor: 2
Discuss This Tutorial
Advertisement

Sponsored By...
Powered By...