Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFLocation Not Redirecting Correcting 1

Status
Not open for further replies.

dennis1000

Programmer
Nov 30, 2002
7
US
I am attempting to set-up a method to count click-throughs on ad pages for a client.

I have set up my links for the ads as: Specific example is
bannerclick.cfm?goto=tour.acp?id=11794&genre=gay&trial=0&HHID=1221


Language for the .cfm page is:

<CFQUERY datasource=&quot;ads&quot;>
Update bannerads
set Clicks=Clicks + 1
where LINKURL='#goto#'
and HHID =#HHID#

</CFQUERY>

<CFLOCATION url=&quot;#goto#&quot;>

From my testing, the counting of clicks seems to working correctly, but it appears CF is cutting off part of the link url. My guess is that it is attempting to read it. I have attempted quotes around the url address to keep it together, but receive a CF syntax error.

Any thoughts? Thanks in advance
 
Can you be more clear on what is happening?

Are you getting an error(s)?
 
Not sure if I can explain it better so I set up an example at Two links are provided. The first as it would be in straight html. The second as this same link is processed through CF. Note that the coding for the link specifies a genre of content. When it goes through the CF coding to seems to default to the sponsor's home page or a 404 error page, presumably because part of the coding has been cut off by CF. Hope this helps.
 
dennis1000, try putting the <CFLOCATION> inside of a <CFIF><CFELSE>

Like:
<cfif queryname NOT EQ #HHID#>
<cflocation URL=&quot;somepage.cfm&quot;>
<cfabort>
</cfif>


Reality continues to ruin my life...
 
My read of your suggestion says to set up a separate page for each ad to send the visitor to where the ad link can be clicked to go to the sponsored site?
 
On the calling page where you have:

You will need to swap the ? delimiter at &quot;tour.acp?id=11794&quot; with an ampersand - ie. &quot;tour.acp&id=11794&quot;.


Then on the template that contains the cflocation tag, add this script. It will rebuild the url vars and redirect the user.

(There's probably a cleaner way to do this - [Carl? Ecobb? Anyone?], but hopefully you'll get the idea of what needs to happen)

<!--- Template that contains the cflocation tag --->
<cfif ISDEFINED(&quot;url.goto&quot;)>
<!--- Build the url var --->
<cfset locUrlString=StructFind(url,&quot;goto&quot;)>
<cfset locTemp=StructDelete(url,&quot;goto&quot;)>
<cfset locCounter=0>

<cfloop collection=&quot;#url#&quot; item=&quot;i&quot;>
<cfset locCounter=locCounter + 1>
<cfif locCounter GT 1>
<cfset locUrlString=locUrlString & &quot;&&quot; & i & &quot;=&quot; & StructFind(url,i)>
<cfelse>
<cfset locUrlString=locUrlString & &quot;?&quot; & i & &quot;=&quot; & StructFind(url,i)>
</cfif>
</cfloop>

<!--- Redirect the user --->
<cflocation url=&quot;#locUrlString#&quot;>
</cfif>

Note:
The reason why it &quot;appeared&quot; as though cf was cutting the url string is due to the fact that you included a second ? in the string. CF doesn't care about the fact that the first url var (goto) is a reference to a new page - CF just knows that the value of url.goto is &quot; Therefore, the second ? in the string (?id=11794) denotes the end of all your url vars.

So I guess, technically, CF IS cutting off the string, but you have to realize that CF SHOULD cut it off.
 
Thanks Tooled. Yes, I realized CF was probably cutting it off and it probably should, that's why I was initially attempting quotes around the url that did not work due to a syntax error.

I attempted your suggested coding. I am not completely sure what you are doing here. Am still trying to digest.

We did make progress as the result showed the url sent to the browser. The problem with the cutting of the url appears to be solved. However, the click is no longer being recorded and CF is adding the ID (HHID) that I am assigning to it to track clicks to the sponsored url, but at least it displays it.

What I am getting in the above example is

When it should be
Here's the complete language in the template as it now stands:

<CFQUERY datasource=&quot;ads&quot;>
Update bannerads
set Clicks=Clicks + 1
Where HHID =#HHID#
and url='#goto#'
</CFQUERY>


<!--- Template that contains the cflocation tag --->
<cfif ISDEFINED(&quot;url.goto&quot;)>
<!--- Build the url var --->
<cfset locUrlString=StructFind(url,&quot;goto&quot;)>
<cfset locTemp=StructDelete(url,&quot;goto&quot;)>
<cfset locCounter=0>
<cfloop collection=&quot;#url#&quot; item=&quot;i&quot;>
<cfset locCounter=locCounter + 1>
<cfif locCounter GT 1>
<cfset locUrlString=locUrlString & &quot;&&quot; & i & &quot;=&quot; &
StructFind(url,i)>
cfelse>
<cfset locUrlString=locUrlString & &quot;?&quot; & i & &quot;=&quot; &
StructFind(url,i)>
</cfif>
</cfloop>

<!--- Redirect the user --->
<cflocation url=&quot;#locUrlString#&quot;>
</cfif>

Am I going to run into trouble with other items like &quot;+&quot; and &quot;-&quot; signs in the url of the sponsor being read by CF?

If I eliminated the sponsor url and its goto statement and pulled the sponsor's url from a database so the banner link were something like and I going to run into the same difficulty when I get to the CFLocation statement?
 
I don't understand what you mean by &quot;However, the click is no longer being recorded and CF is adding the ID (HHID) that I am assigning to it to track clicks to the sponsored url, but at least it displays it.&quot;

Regarding &quot;trouble with other items like &quot;+&quot; and &quot;-&quot;. No, you shouldn't run into problems with the +,- like you did with the &quot;?&quot; and &quot;&&quot;.

Keep in mind that the initial problem that you were experiencing was due to your url syntax. I'm sure you are aware of the fact that url vars are delimited by an initial ? and all following vars with &'s.

Your initial query string was written as:

?goto=?id=11794&genre=gay&trial=0&HHID=1221

Notice the two ?'s. This was the root of your problem. My point is, using a + or - has nothing to do with url variable syntax, therefore + and - chars will not break your code.

Regarding, &quot;pulled the sponsor's url from a database&quot; - You will not run into the SAME problem as the url issue. But you may run into other problems - depending on how you write your code of course.
 
I understand the ? issue clearly.

What I am saying about the click is that it is no longer adding a click into the database after a link is clicked.

The second point I was saying is that my identifier HHID is being added to the url string causing an error now. See above example. The first one is the product of CFlocation. HH1221 is being added to the url string and it should not be there.

By &quot;at least displays&quot;, I mean I am seeing the url as it is sent now. Didn't before. It is how I know the errant HHID is being added.
 
To troubleshoot the Click issue, add the debug attribute to your query then abort the page:

<CFQUERY datasource=&quot;ads&quot; debug=&quot;yes&quot;>
Update bannerads
set Clicks=Clicks + 1
Where HHID =#HHID#
and url='#goto#'
</CFQUERY>

<cfabort>

After you run the above query, check what values are being processed in the HHID and url statements. It's possible that your WHERE condition is returning zero results, therefore the UPDATE is not being ran. In other words, confirm that there is a record in your db table that matches your WHERE condition.

On a side note: Remember to scope your variables -
Where HHID =#url.HHID#
and url='#url.goto#'

Also, if you are gonna go with the code that I posted previously, then it would make sense to place the UPDATE query inside of the <cfif ISDEFINED(&quot;url.goto&quot;)> condition.

Regarding the HHID:
You can remove that url var simply by deleting the key from the structure.

ie:
<cfset locUrlString=StructFind(url,&quot;goto&quot;)>
<cfset locTemp=StructDelete(url,&quot;goto&quot;)>
<cfset locTemp=StructDelete(url,&quot;HHID&quot;)>
.
.
.
.

Maybe I should be clear as to what's going on here:

Note that CFAS groups url variables into a CF Structure. To see what that looks like run <cfdump var=#url#>.

All that structure stuff is implemented so that we can dynamically grab all url vars that may have been passed to the page. (I make it a habit to make templates as dynamic as possible). On the other hand, if you know the name of all your url vars at development time - and you will ALWAYS know this info, then you may rather just hard code the variable names. Something like the following:

<cfif ISDEFINED(&quot;url.goto&quot;)>
<cfset locGoto=url.goto>
</cfif>

<cfif ISDEFINED(&quot;url.hhid&quot;)>
<cfset locHHID=url.hhid>
</cfif>

<cfif ISDEFINED(&quot;url.id&quot;)>
<cfset locID=url.id>
</cfif>

<cfif ISDEFINED(&quot;url.genre&quot;)>
<cfset locGenre=url.genre>
</cfif>

<cfif ISDEFINED(&quot;url.trial&quot;)>
<cfset locTrial=url.trial>
</cfif>

<cfset locURLString=locGoto & &quot;?id=&quot; & locID& &quot;&genre=&quot; & locGenre & &quot;&trial=&quot; & locTrial>

<CFQUERY datasource=&quot;ads&quot;>
Update bannerads
set Clicks=Clicks + 1
Where HHID =#locHHID#
and url='#locGoTo#'
</CFQUERY>

<cflocation url=#locURLString#>
 
After using this coding, it was clear that CF was including my assigned ID to the sponsor's link and that was what was causing the issue. I started from square one, placed the sponsor's url into the database and called it up using CFLocation. Works like a charm. Thanks for your help in identifying the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top