Jump to content

How To Set ColdFusion Sesssion using Action Hooks


openmind

Recommended Posts

Seeing as this had me stumped for quite some time I thought I would post the solution here.

 

Anyway, I needed a way to set a ColdFusion session for the userID of the logged in WHMCS user so I could use it in areas outside the client account area. Now as ColdFusion works server side and you can't easily access PHP sessions with it I tried a million different ways until I hit on this simple method...

 

1) Create a new action hook in /includes/hooks and add the following code:

 

<?php
function login_redirect($vars) {
   //url-ify the data for the redirect
   foreach($vars as $key=>$value) { $vars_string .= $key.'='.$value.'&'; }
       rtrim($vars_string,'&');

   header('Location: /your_coldfusion_file.cfm?' . $vars_string); 
exit;
}
add_hook("ClientLogin",1,"login_redirect"); 
?>

 

2) Create the file to receive the URL so in the example above your_coldfusion_file.cfm and add this:

<cfset session.isloggedin=True>
<cfset session.custid=url.userid>
<cflocation url="../portal/clientarea.php" addtoken="no">

 

On logging in the client bounces off your ColdFusion file, sets the session vars and returns back to the client area. Now you have the userID stored in a ColdFusion session you can use it outside of the portal in ColdFusion files.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated