JulesR Posted May 15, 2014 Share Posted May 15, 2014 As subject, trying to get the clients logged in status from outside of the WHMCS folder but having no luck at all. I assume the WHMCS cookies are set on the installation folder only and cannot be retrieved on the global domain. I've tried numerous scripts and session hacks but can't get this working at all. Any ideas? Link to comment Share on other sites More sharing options...
Infopro Posted May 15, 2014 Share Posted May 15, 2014 Might be something useful for you in this thread, not exactly related: Client Register from Outside WHMCS - WHMCS Forums Link to comment Share on other sites More sharing options...
JulesR Posted May 16, 2014 Author Share Posted May 16, 2014 Thanks for the reply. Unfortunately that doesn't help Link to comment Share on other sites More sharing options...
jclarke Posted May 16, 2014 Share Posted May 16, 2014 You can require the init.php script from outside of the WHMCS folder and you will then be able to access $_SESSION['uid'], if it is set then the user is logged in. require("whmcsdirectory/init.php"); $whmcs_user_id = $_SESSION['uid']; This could interfere though if the script you are adding this to has it's own session management. The other option would be to use javascript. Take a look at the feeds directory, you could create a simple feed that requires init and adds anything you want to the page you include the javascript on. <?php require("../init.php"); if (isset($_SESSION['uid'])) { echo "document.write('Client Logged in');"; exit; } else { echo "document.write('Client Logged out');"; exit; } ?> Then you would include the javascript on the other page: <script language="javascript" src="whmcsfolder/feeds/loggedin.php"></script> Link to comment Share on other sites More sharing options...
JulesR Posted May 16, 2014 Author Share Posted May 16, 2014 (edited) You can require the init.php script from outside of the WHMCS folder and you will then be able to access $_SESSION['uid'], if it is set then the user is logged in. Have you actually tried this? The only session variable passed back is the tkval one for us, so I'm curious if WHMCS has changed this or we have a problem with our setup. We've tried something similar to what you suggested, but still no dice. The session only works correctly from the WHMCS installation folder and not outside of it. Edited May 16, 2014 by JulesR Link to comment Share on other sites More sharing options...
jclarke Posted May 16, 2014 Share Posted May 16, 2014 Yes, it works for me. Link to comment Share on other sites More sharing options...
Angelo Posted October 31, 2017 Share Posted October 31, 2017 A better and more secure way to get WHMCS data to an external website is to interact with whmcs libraries and fetch almost all data of your installation. I have installed whmcs on a subfolder [clients]of my main domain, e.g. https://my-domain.com/clients/ . I have created a folder /scripts, e.g. https://my-domain.com/clients/scripts/ and there i have created a php file (get_whmcs_data.php) which fetches all data of whmcs installation. From login session to clients data (name, email, address, country etc.) to all of domain name tlds and its prices, so to call them to my main website. So when i change the prices at my whmcs installation, they will be changed and to my website. get_whmcs_data.php <?php define('WHMCS_ROOT', (dirname(__FILE__).'/../')); require(WHMCS_ROOT . "init.php"); require(WHMCS_ROOT . "includes/clientfunctions.php"); require(WHMCS_ROOT . "includes/orderfunctions.php"); require(WHMCS_ROOT . "includes/invoicefunctions.php"); require(WHMCS_ROOT . "includes/configoptionsfunctions.php"); require(WHMCS_ROOT . "includes/cartfunctions.php"); require(WHMCS_ROOT . "includes/domainfunctions.php"); use WHMCS\Database\Capsule; /* *** GET CLIENT LOGIN STATUS AND CLIENT DETAILS *** */ if ($_SESSION['uid']) { $login_session=true; foreach (Capsule::table('tblclients')->get() as $client) { $first_name=$client->firstname . PHP_EOL; $last_name=$client->lastname . PHP_EOL; $company_name=$client->companyname . PHP_EOL; $email_address=$client->email . PHP_EOL; $client_address1=$client->address1 . PHP_EOL; $client_city=$client->city . PHP_EOL; $client_phonenumber=$client->phonenumber . PHP_EOL; $client_country=$client->country . PHP_EOL; } }else{ $login_session=false; } /* *** GET CART ITEMS *** */ $products = (isset($_SESSION["cart"]["products"]) && is_array($_SESSION["cart"]["products"])) ? $_SESSION["cart"]["products"] : array(); $addons = (isset($_SESSION["cart"]["addons"]) && is_array($_SESSION["cart"]["addons"])) ? $_SESSION["cart"]["addons"] : array(); $domains = (isset($_SESSION["cart"]["domains"]) && is_array($_SESSION["cart"]["domains"])) ? $_SESSION["cart"]["domains"] : array(); $renewals = (isset($_SESSION["cart"]["renewals"]) && is_array($_SESSION["cart"]["renewals"])) ? $_SESSION["cart"]["renewals"] : array(); $cart_items = count($products) + count($addons) + count($domains) + count($renewals); /* *** GET CART TOTAL *** */ $currency = getCurrency(); $carttotals = calcCartTotals('',true); $cart_total = ($carttotals['total']) ? $carttotals['total'] : formatCurrency(0); /* *** GET DOMAIN TLD PRICING *** */ if (!is_numeric($currency)) { $currency = array(); } else { $currency = getCurrency('', $currency); } if (!$currency || !is_array($currency) || !isset($currency['id'])) { $currency = getCurrency(); } $freeamt = formatCurrency(0); $tldslist = getTLDList(); foreach ($tldslist AS $tld) { $tldpricing = getTLDPriceList($tld, true); $firstoption = current($tldpricing); $year = key($tldpricing); $transfer = ($firstoption["transfer"] == $freeamt) ? $_LANG['orderfree'] : $firstoption["transfer"]; $domain_tld=$tld; $domain_price=$firstoption["register"]; $x = $domain_tld; //Here you can add all of your domain tlds so you can fetch the prices at your main website while($x == '.com') { $domain_price_com=$domain_price; $x++; } while($x == '.net') { $domain_price_net=$domain_price; $x++; } while($x == '.org') { $domain_price_org=$domain_price; $x++; } while($x == '.biz') { $domain_price_biz=$domain_price; $x++; } while($x == '.info') { $domain_price_info=$domain_price; $x++; } while($x == '.eu') { $domain_price_eu=$domain_price; $x++; } while($x == '.host') { $domain_price_host=$domain_price; $x++; } } ?> To my main website https://my-domain.com i have created a init.php file where i include the get_whmcs_data.php file and fetch all of the data i need/ init.php <?php include('clients/scripts/get_whmcs_data.php'); if($login_session): echo 'Loggedin: ' .$first_name.' '.$last_name. ', '.$company_name. ', '.$email_address.', '.$client_address1.', '.$client_city.', '.$client_phonenumber.', '.$client_country; else: echo 'Not Loggedin'; endif; echo '<br /><br />'; echo 'Items in Cart: '.$cart_items.', '.$cart_total; echo '<br /><br />'; echo '.com: ' .$domain_price_com; echo '<br />'; echo '.net: ' .$domain_price_net; echo '<br />'; echo '.org: ' .$domain_price_org; echo '<br />'; echo '.biz: ' .$domain_price_biz; echo '<br />'; echo '.info: ' .$domain_price_info; echo '<br />'; echo '.eu: ' .$domain_price_eu; echo '<br />'; echo '.host: ' .$domain_price_host; echo '<br />'; PHP code inside init.php file is a simple example how easy you can fetch whmcs data to your website and save you time from editing prices and updates! You can fetch almost all client and products data of whmcs! I hope i helped you! Link to comment Share on other sites More sharing options...
Recommended Posts