Sample code for using FoxyCart's shared authentication (available in FoxyCart v051+) in PHP.
Implementing FoxyCart's shared authentication functionality is for advanced users familiar. This code will get you started, but will very like need to be modified to fit your needs. See the shared authentication documentation for more details.
<?php /* FoxyCart Shared Authentication for FoxyCart v051 Two options: Option 1: If you have an existing session-based authentication include file, then include it at the top of this file and use this file as your shared authentication end point in the FoxyCart admin. Ideally, your authentication script should ideally know which FoxyCart customer_id is logged in. Option 2: Include this file in your existing authentication check to create a new, publicly accessible shared authentication endpoint which you'll configure in the FoxyCart admin. Be sure no output has taken place yet, since this file will do a redirect every time. */ /*************** EDIT THESE VALUES *******************/ // Put in a boolean value here which represents if the // current user session is authenticated. $user_is_authenticated = true; // Put in your FoxyCart api / datafeed access key here. // This value should match the value setup in your // FoxyCart admin under "advanced". $foxycart_api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // Put in your full foxycart store domain here. $foxycart_domain = 'MYDOMAIN'; // If the user is not logged in, do you still want to // allow them to proceed to checkout? $allow_non_auth_checkout = true; // if not, you must specify a redirect page (such as your login page?) $redirect_url = 'http://yourdomain.com/login.php'; // Put in your database query or session variable here // for the current logged in user's FoxyCart customer_id $foxycart_customer_id = 123456; /**************************************************/ $return_hash = ''; $redirect_url = ''; $customer_id = 0; $timestamp = 0; $fcsid = ''; if ($user_is_authenticated) { $customer_id = $foxycart_customer_id; } if ($allow_non_auth_checkout) { $redirect_url = 'https://' . $foxycart_domain . '/checkout?fc_auth_token='; } else { if (!$user_is_authenticated) { header('Location: ' . $redirect_url); exit(); } } if (isset($_REQUEST['timestamp']) && isset($_REQUEST['fcsid'])) { $fcsid = $_REQUEST['fcsid']; $timestamp = $_REQUEST['timestamp'] + (60 * 30); // valid for 30 minutes; } $return_hash = sha1($customer_id . '|' . $timestamp . '|' . $foxycart_api_key); $full_redirect = $redirect_url . $return_hash . '&fc_customer_id=' . $customer_id . '×tamp=' . $timestamp . '&fcsid=' . $fcsid; header('Location: ' . $full_redirect); ?>