Important alert: (current site time 5/26/2015 11:09:25 AM EDT)

VB icon


Submitted on: 4/23/2007 5:13:22 PM
By: Rabid Nerd Productions  
Level: Beginner
User Rating: Unrated
Compatibility: Cold Fusion 5, Cold Fusion MX
Views: 14177
author picture
(About the author)
     This code allows for simulated browser based interaction with remote websites.
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
// for :GetCookies
De-versioning adaptation of open source Cold Fusion MX script by rickroot:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
// Name: GetCookies
// Description:This code allows for simulated browser based interaction with remote websites.
// By: Rabid Nerd Productions
// Inputs:Cookies to be set as returned by remote servers in response headers (cfhttp.header)
// Returns:GetCookies variable as an array
// Assumes:Example Usage:
A site where the page sneaky.php requires a set of server cookies and a session variable set in a form field from the homepage.
Example Session Field Value:
<input type="hidden" name="__SESSION" value="dhu}FR_VKROJeiCNWJrif">
<cfhttp url="" method="GET" useragent="#cgi.http_user_agent#">
<cfset cookies = getCookies(cfhttp.header)>
<cfset getstate = cfhttp.filecontent>
<cfset getstate = replacenocase(getstate,"__SESSION"" value=""",chr(7))>
<cfset getstate = listgetat(getstate,2,chr(7))>
<cfset getstate = listgetat(getstate,1,"""")>
<cfhttp url="" method="POST" useragent="#cgi.http_user_agent#">
	<cfhttpparam name="__SESSION" value="#SESSION#" type="FORMFIELD">
<cfloop from="1" to="#arrayLen(cookies)#" step="1" index="i">
	<cfhttpparam type="cookie" name="#cookies[i].NAME#" value="#cookies[i].VALUE#">
// Side Effects:Edited - "WriteOutput" to screen of cookie values for debug use were left in in initial posting... Have now commented them below..
//This code is copyrighted and has// limited warranties.Please see details.//**************************************

function getCookies(headers){
cookies = arraynew(1);
thiscookie = structnew();
for (i=1;i lte listlen("#headers#","#chr(10)#");i=i+1) {
	header = listgetat(headers,i,chr(10));
	if(reFind("^Set-Cookie: ",header) gt 0){
		acookie = reReplace(header,"^Set-Cookie: ","","ALL");
		thisCookie = StructNew();
		for (ii=1;ii lte listlen("#acookie#",";");ii=ii+1){
			// writeoutput(crumb);
			// writeoutput("<p><hr></p>");
			crumb = listgetat(acookie,ii,";");
			crumb = trim(crumb);
			paramName = listgetat(crumb,1,"=");
			if (listlen(crumb,"=") gt 1) {paramValue = listgetat(crumb,2,"=");} else {paramValue=" ";}
			if(paramName eq "expires"){
				thisCookie.expires = paramValue;
			} else {
			if(paramName eq "path"){
				thisCookie.path = paramValue;
			} else {
			if(paramName eq "domain"){
				thisCookie.domain = paramValue;
			} else {
			if(paramName eq "secure"){ = paramValue;
			} else { = paramName;
				thisCookie.value = paramValue;
return cookies;

Other 4 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.