Will Hosting Posted June 14, 2011 Share Posted June 14, 2011 I've been trying recently to make the login page on our website homepage show a link "Go to client portal" when the user is logged into WHMCS in the portal but show the login form when they're not. This PHP page is outside of WHMCS, hosted in the public_html/ folder and WHMCS is in the portal/ folder. I've tried using PHP sessions but using $_SESSION['uid'] has been getting me nowhere and refuses to work at all. I was wondering if anyone had finally gotten this to work and if so, please share some example code, I know many other users are looking for this same solution too. Thanks! 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted June 16, 2011 Share Posted June 16, 2011 Is WHMCS and the website hosted on different domains/subdomains? I.e. http://www.domain.com vs. clients.domain.com. If so, the session is not going to carry over for you. 0 Quote Link to comment Share on other sites More sharing options...
microbolt Posted June 16, 2011 Share Posted June 16, 2011 Yep laszlof is right. And if the mods ever approve my first post I made a couple days here ago you can see the solution I use on my site. It must of picked up something in there as a URL and blocked it as potential spam, hehe. 0 Quote Link to comment Share on other sites More sharing options...
Iceman Posted November 4, 2011 Share Posted November 4, 2011 Yep laszlof is right. And if the mods ever approve my first post I made a couple days here ago you can see the solution I use on my site. It must of picked up something in there as a URL and blocked it as potential spam, hehe. Howdy, We are moving whmcs to it's own subdomain of the main website, in it's own VPS. So, if you are willing to share via post or PM, please?... I'm very interested in your solution. Cheers, Paul 0 Quote Link to comment Share on other sites More sharing options...
microbolt Posted November 4, 2011 Share Posted November 4, 2011 Here's the code I have on my website. But, it won't work carry state across different subdomains. This assumes your installed in /clients <?php require("clients/dbconnect.php"); if ($_SESSION['uid']) { $query="SELECT * FROM tblclients WHERE id='" .sanitize($_SESSION['uid']) . "'"; $result = mysql_query($query) or die(mysql_error()); if($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $clientsdetails['firstname']=$row['firstname']; $clientsdetails['lastname']=$row['lastname']; $clientsdetails['email']=$row['email']; } echo "Welcome Back, <strong>".($row['firstname'])."</strong> <img src=\"/clients/templates/portal/images/icons/details.gif\" alt=\"My Details\" width=\"16\" height=\"16\" border=\"0\" class=\"absmiddle\" /> <a href=\"/clients/clientarea.php?action=details\" title=\"My Details\"><strong>My Details</strong></a> <img src=\"/clients/templates/portal/images/icons/logout.gif\" alt=\"Logout\" width=\"16\" height=\"16\" border=\"0\" class=\"absmiddle\" /> <a href=\"/clients/logout.php\" title=\"Logout\"><strong>Logout</strong></a>"; } else { echo "Please <a href=\"/clients/clientarea.php\" title=\"Login\"><strong>Login</strong></a> or <a href=\"/clients/register.php\" title=\"Register\"><strong>Register</strong></a>"; } ?> 0 Quote Link to comment Share on other sites More sharing options...
Iceman Posted November 4, 2011 Share Posted November 4, 2011 Thanks for that. I edited my last post, but my edits didnt save. Anyway, what I meant to add a few minutes later was that I found a very simple solution (after many hours of trial and error.... lol ) PROBLEM: WHMCS is installed on another subdomain of main website tld. eg Main website http://www.yourdomain.com and WHMCS on subdomain.yourdomain.com SOLUTION: Add the following to your .htaccess for the Main website (which needs session info from the whmcs subdomain). php_value session.cookie_domain .yourdomain.com Works perfectly, (although I haven't tested this for the main website on domain.com without the www yet.) Cheers, Paul 0 Quote Link to comment Share on other sites More sharing options...
microbolt Posted November 4, 2011 Share Posted November 4, 2011 Lol, I should of thought of doing that. I've done that before on another project I did for a customer. It should work. The only issue you may have if WHMCS is going to be in its own VPS then you might have problems sharing the DB with your main website. Probably will have to install WHMCS twice and point them to the same DB if on different servers. 0 Quote Link to comment Share on other sites More sharing options...
Iceman Posted November 4, 2011 Share Posted November 4, 2011 Yup, I feel like I wasted half my day... all for 1 line of "code". The the only thing we needed (for the main website) was for it to know if a Client was already logged into whmcs. We made the whmc install look exactly like the main site. In browsing the site the only difference a visitor may see is that the subdomain url will change from "www" to "clients" when various pages are accesed. What we are now able to do is show a "Login Form" on all pages when not logged in. Logged in visitors see a "Client Area" button and a "Logout Button". We are using Wordpress for the main website and needed to really lock down the whmcs database so that we can store CC details (and PCI of course!). At this point we can not see the need for the main website to have direct access to the whmcs db. But, can you think of some situations where perhaps the main website could need direct access to the db? Cheers, Paul 0 Quote Link to comment Share on other sites More sharing options...
microbolt Posted November 4, 2011 Share Posted November 4, 2011 Only if your wanting to query information on them when their logged on. Like for instance: "Welcome back {Customer Name}" 0 Quote Link to comment Share on other sites More sharing options...
Iceman Posted November 4, 2011 Share Posted November 4, 2011 Ahh yes, already came across that one. But a simple," You are Logged On" or similar will do. They will have to wait until they go to the Client Area before we call them by name. 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.