Jump to content

WHMCS Session Login?


Recommended Posts

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! 8)

Link to comment
Share on other sites

  • 4 months later...
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

Link to comment
Share on other sites

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>";
}
?> 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Yup, I feel like I wasted half my day... all for 1 line of "code". :lol::roll:

 

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated