LondonWebSolutions Posted March 9, 2012 Share Posted March 9, 2012 Hi, I am using a light box for my clients to login from the homepage of my website. The end user clicks "login" and the light box pops up displaying a login form. For now I have used the post action within the form "post" action="http://www.yourdomain.com/whmcs/dologin.php" which directs the end user to their account perfectly. However I would like to know how to get a response from WHMCS so that if they were to go back to the homepage it would say their username and logout etc instead of "login" still. I think it is bad ux for them to have to log back in every time they navigate away from the WHMCS pages. I would be grateful if anyone could show me how to do this? Thanks, Matt 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted March 9, 2012 Share Posted March 9, 2012 Is WHMCS and your homepage on the same subdomain? If so, you can simply check the session for uid to see if they're logged in or not, and then use the API to fetch their information. 0 Quote Link to comment Share on other sites More sharing options...
LondonWebSolutions Posted March 12, 2012 Author Share Posted March 12, 2012 Thank you for replying. Yes they are on the same sub domain. Ok, How would I go about doing this? 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted March 12, 2012 Share Posted March 12, 2012 something like this maybe (assuming whmcs is installed into the "whmcs" directory) <?php if (isset($_SESSION['uid'])) { $adminid = 1; // ID of admin to execute API functions as (must have API access) include("whmcs/dbconnect.php"); include("whmcs/includes/functions.php"); $res = localAPI('getclientsdetails', array('clientid'=>$_SESSION['uid']), $adminid); if ($res['result'] == 'success') { $firstname = $res['firstname']; $lastname = $res['lastname']; $email = $res['email']; $loggedin = true; } else { $loggedin = false; } else { $loggedin = false; } ?> <html> <head> <!-- header --> </head> <body> <!-- Some body code here --> <?php if ($loggedin) { ?> Hello <?= $firstname; ?> <?= $lastname; ?>! <br /> <a href="whmcs/logout.php">Logout</a> <?php } else { ?> <!-- Display login form here --> <?php } ?> This is completely untested, and requires shorttags to be enabled in PHP to work, assuming I didnt make any mistakes. 0 Quote Link to comment Share on other sites More sharing options...
LondonWebSolutions Posted March 12, 2012 Author Share Posted March 12, 2012 something like this maybe (assuming whmcs is installed into the "whmcs" directory) <?php if (isset($_SESSION['uid'])) { $adminid = 1; // ID of admin to execute API functions as (must have API access) include("whmcs/dbconnect.php"); include("whmcs/includes/functions.php"); $res = localAPI('getclientsdetails', array('clientid'=>$_SESSION['uid']), $adminid); if ($res['result'] == 'success') { $firstname = $res['firstname']; $lastname = $res['lastname']; $email = $res['email']; $loggedin = true; } else { $loggedin = false; } else { $loggedin = false; } ?> <html> <head> <!-- header --> </head> <body> <!-- Some body code here --> <?php if ($loggedin) { ?> Hello <?= $firstname; ?> <?= $lastname; ?>! <br /> <a href="whmcs/logout.php">Logout</a> <?php } else { ?> <!-- Display login form here --> <?php } ?> This is completely untested, and requires shorttags to be enabled in PHP to work, assuming I didnt make any mistakes. Hi, thanks for your reply. I couldn't get it to work, is there another way of doing it rather than using the API? 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted March 12, 2012 Share Posted March 12, 2012 Hi, thanks for your reply. I couldn't get it to work, is there another way of doing it rather than using the API? Sure, you could query the database directly if you want. 0 Quote Link to comment Share on other sites More sharing options...
LondonWebSolutions Posted March 12, 2012 Author Share Posted March 12, 2012 Would that be a security risk? 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted March 12, 2012 Share Posted March 12, 2012 Would that be a security risk? Nah, just use the built in sql helper functions for WHMCS. Since you're including the dbconnect.php file from WHMCS as I listed before, there will be no need to add your DB connection details as well. 0 Quote Link to comment Share on other sites More sharing options...
LondonWebSolutions Posted March 13, 2012 Author Share Posted March 13, 2012 (edited) Nah, just use the built in sql helper functions for WHMCS. Since you're including the dbconnect.php file from WHMCS as I listed before, there will be no need to add your DB connection details as well. Sorry to be a pain but because I'm not that familiar with php would you be able to show me how to accomplish this please? Edited March 13, 2012 by LondonWebSolutions Grammer 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.