Picture of Paul Silver

Paul Silver

Making websites for companies and helping advertise them

Have a single variable URL in ColdFusion

Some websites have URLs with only a question mark and one variable, e.g. http://www.blah.com?123 or http://www.blah.com/index.cfm?123.

You can do this with ColdFusion by using CGI.QUERY_STRING. This gives you all of the information after the ? in the URL. As in this case there is only one piece of information you can use it to look up a record in your database.

E.g. in the case of looking up a number as the ID:

URL: http://www.tenpastmidnight.com?123

<CFQUERY NAME="DBRead" DATASOURCE="#Datasource#">
   SELECT Data
   FROM DataBaseName
   WHERE ID = #val(CGI.QUERY_STRING)#
</CFQUERY>

The 'val()' makes sure that the database looks up a number, rather than some nefarious code, see other CF security tips.

More code articles


Paul Silver. February 2004

© 2024 Paul Silver & Silver Web Services Ltd