steelaz Posted June 15, 2008 Share Posted June 15, 2008 Is there a way to check if user is logged in outside of WHMCS area? I want to show WHMCS links in my main site when user is logged in. Is it possible? 0 Quote Link to comment Share on other sites More sharing options...
Adam Posted June 16, 2008 Share Posted June 16, 2008 Is there a way to check if user is logged in outside of WHMCS area? I want to show WHMCS links in my main site when user is logged in. Is it possible? Howdy, I do not believe this is possible as active sessions are not stored in the database. Now if you know PHP and some MySQL commands this can be done with a simple addition to the main page. But information about how many users are logged onto WHMCS should be private and somewhat of a waste, if you ask me. From, Adam 0 Quote Link to comment Share on other sites More sharing options...
steelaz Posted June 16, 2008 Author Share Posted June 16, 2008 Thanks for reply. I don't want information on how many users are logged in. I just want to show client area menu (Invoices, Tickets etc.) alongside main menu if user is logged in. I'll try to push session IDs to database, match them to session cookie and see if it works. 0 Quote Link to comment Share on other sites More sharing options...
Redsign Posted June 16, 2008 Share Posted June 16, 2008 As a dirty hack you could create a subpage of WHMCS that simply has an if statement checking if the user in logged in, then pop it in an iFrame... (waits for people to express their hate for iFrames) Hope this makes sense, Ben 0 Quote Link to comment Share on other sites More sharing options...
minadreapta Posted June 16, 2008 Share Posted June 16, 2008 it's not impossible, you just have to "php require" some config files from whmcs like this: <?php require("whmcs_dir/dbconnect.php"); require("whmcs_dir/includes/functions.php"); require("whmcs_dir/init.php"); if (!empty($GLOBALS['clientsdetails']['id'])) { require_once ("whmcs_dir/includes/clientfunctions.php"); $userdetails = getclientsdetails($GLOBALS['clientsdetails']['id']); } $firstname= $userdetails['firstname']; ?> then, on the appropriate place: <?php if ($_SESSION['loggedinstatus']=="true") { # User is Logged In - put any code you like here echo "<strong>Hello $firstname! You are logged in.</strong> <a href=\"whmcs_dir/logout.php\">(Click for Logout)</a>"; } else { echo "<form method=\"post\" action=\"whmcs_dir/dologin.php?goto=clientarea\" name=\"form1\"> <strong>Client Login: </strong> <input name=\"username\" type=\"text\" value=\"Email\" size=\"18\" /> <input name=\"password\" type=\"password\" value=\"password\" size=\"18\" /> <input name=\"image\" type=\"image\" src=\"images/go.png\" style=\"padding:0px;\" /></form>"; } ?> 0 Quote Link to comment Share on other sites More sharing options...
steelaz Posted June 17, 2008 Author Share Posted June 17, 2008 Thanks for the snippet minadreapta!! All I wanted was logged-in status, but this is much better. 0 Quote Link to comment Share on other sites More sharing options...
dordal Posted July 13, 2008 Share Posted July 13, 2008 Just a quick note to say that $_SESSION['loggedinstatus']=="true" no longer works (as of 3.6.2 I believe) You now need $_SESSION['uid'] > 0 0 Quote Link to comment Share on other sites More sharing options...
mattpark Posted July 13, 2008 Share Posted July 13, 2008 Hi Guys, Any idea how to make this work with a page outside of the WHMCS install domain? i.e. Example testpage - http://www.yourdomain.com/testpage.php WHMCS install - subdomain.yourdomain.com This code works fine if in place in the same sub domain, however moving it out of there on to another subdomain breaks it.... 0 Quote Link to comment Share on other sites More sharing options...
aushosts Posted July 14, 2008 Share Posted July 14, 2008 We have done this on our site. If the customer isn't logged in at the top of the page it saids "Login to My Account". If they are logged in it saids "Welcome Back Bary" or what ever the customers name is. E.g --> http://www.aushosts.com.au/myfiles/logged-in.jpg but this is on the same hostname. Its not possiable from what I could see to grab the session info if its on a different hostname - we wanted to use https://myaccount.aushosts.com.au but that would mean we'd have to do lots of extra coding to make what we want to do possiable. You will need to use an iframe or AJAX or something loading off the subdomain to grab the season info and present it to the visitor. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS CEO Matt Posted July 14, 2008 WHMCS CEO Share Posted July 14, 2008 A way of doing this would be to create a file in the WHMCS folder, named getuserid.php for example, with the code below: <?php session_start(); echo $_SESSION["uid"]; ?> And then on the external pages, just do: <?php $userid = file_get_contents("http://www.yourdomain.com/whmcs/getuserid.php"); if ($userid) { echo "Logged In"; } else { echo "Logged Out"; } ?> Not tested it but can't see any reasons why that wouldn't work. Matt 0 Quote Link to comment Share on other sites More sharing options...
aushosts Posted July 14, 2008 Share Posted July 14, 2008 Good stuff LOL - That would have saved us over $200 in new SSL certificates, we should have asked first 0 Quote Link to comment Share on other sites More sharing options...
mattpark Posted July 14, 2008 Share Posted July 14, 2008 Excellent! Might you suggest the best way to echo the users first and lastname when logged in too? Thanks for your help. Matt 0 Quote Link to comment Share on other sites More sharing options...
aushosts Posted July 14, 2008 Share Posted July 14, 2008 if ($_SESSION['uid']) { echo "Welcome Back, " . $clientsdetails['firstname'] . " " . $clientsdetails['lastname'] . "; } else { echo "Login to My Account"; } 0 Quote Link to comment Share on other sites More sharing options...
othellotech Posted July 14, 2008 Share Posted July 14, 2008 that works to tell you if they've *ever* logged in, need to have some way to clear the "session" files when the session closes - say an hourly cron job to delete those > 1hour old 0 Quote Link to comment Share on other sites More sharing options...
poppabear Posted February 11, 2009 Share Posted February 11, 2009 A way of doing this would be to create a file in the WHMCS folder, named getuserid.php for example, with the code below: <?php session_start(); echo $_SESSION["uid"]; ?> And then on the external pages, just do: <?php $userid = file_get_contents("http://www.yourdomain.com/whmcs/getuserid.php"); if ($userid) { echo "Logged In"; } else { echo "Logged Out"; } ?> Not tested it but can't see any reasons why that wouldn't work. Matt I know this thread is old, however i would like to share my input. The code used above will not work as expected as the function file_get_contents(); is meant to read the contents of said file. It will always return true if the file exists. The function will return the entire php source of the file and at that point you would be required to parse the data with string manipulation. If using an include() or require() the script will fail because of the session was already started and will not pass the data to the other domain. I have not found a solution to this as of yet, however i will make sure i include the findings when i do. I will find a workaround, just have to make sure it will be secure. 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted February 12, 2009 Share Posted February 12, 2009 I know this thread is old, however i would like to share my input. The code used above will not work as expected as the function file_get_contents(); is meant to read the contents of said file. It will always return true if the file exists. The function will return the entire php source of the file and at that point you would be required to parse the data with string manipulation. If using an include() or require() the script will fail because of the session was already started and will not pass the data to the other domain. I have not found a solution to this as of yet, however i will make sure i include the findings when i do. I will find a workaround, just have to make sure it will be secure. Well, the biggest reason why it wouldnt work is because the server would be reading that page, not the user. Hence, there would be no active session for it to read because the server itself is never logged in, the clients browser session would be. 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted May 19, 2009 Share Posted May 19, 2009 Has anyone figured out a good way to do this? i havent had time lately to look into it, but wanted to see if anyone else had figured a way to do it. To bad whmcs can be set to allow its sessions/cookies to work amongst multiple domains (aka, secure.domain.com and domain.com). 0 Quote Link to comment Share on other sites More sharing options...
siforek Posted May 19, 2009 Share Posted May 19, 2009 Has anyone figured out a good way to do this? i havent had time lately to look into it, but wanted to see if anyone else had figured a way to do it. To bad whmcs can be set to allow its sessions/cookies to work amongst multiple domains (aka, secure.domain.com and domain.com). Why don't you just create your site within WHMCS by adding additional WHMCS pages? That way you'll then have access to everything. 0 Quote Link to comment Share on other sites More sharing options...
MACscr Posted May 19, 2009 Share Posted May 19, 2009 Why don't you just create your site within WHMCS by adding additional WHMCS pages? That way you'll then have access to everything. Maybe because WHMCS is only a small segment of my site and definitely should not be the foundation of it? I can easily access any information in whmcs through its db from outside of whmcs, obviously except the session info. Trying to figure out a secure way to do that, which is obviously why I am posting here under this particular thread subject. 0 Quote Link to comment Share on other sites More sharing options...
siforek Posted May 27, 2009 Share Posted May 27, 2009 Try this: something.php (located in the WHMCS dir <?php require("dbconnect.php"); if ($_SESSION['uid']) { $isloggedin = 'true'; } ?> yoursite.php <?php include('pathto/whmcs/isloggedin.php'); if ($isloggedin){ echo "logged in to whmcs"; } ?> 0 Quote Link to comment Share on other sites More sharing options...
e[X]treme[Z] Posted June 8, 2009 Share Posted June 8, 2009 Did anybody get this to work? 0 Quote Link to comment Share on other sites More sharing options...
siforek Posted June 8, 2009 Share Posted June 8, 2009 I did.. Posted to code above.. 0 Quote Link to comment Share on other sites More sharing options...
e[X]treme[Z] Posted June 9, 2009 Share Posted June 9, 2009 I did.. Posted to code above.. Sorry but I'm not that good with php programming. Do you have the complete code? 0 Quote Link to comment Share on other sites More sharing options...
siforek Posted June 9, 2009 Share Posted June 9, 2009 treme[Z];108386']Sorry but I'm not that good with php programming. Do you have the complete code? That is the complete code. the first part you put in your WHMCS directory, the second part you put somewhere else and change the path to point to the first part. 0 Quote Link to comment Share on other sites More sharing options...
e[X]treme[Z] Posted June 10, 2009 Share Posted June 10, 2009 1st part i save as isloggedin.php 2nd part I save as something.php http://seahosting.net/yourside.php But I got a blank page.. 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.