Jump to content

loggedin() outside WHMCS


steelaz

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 weeks later...

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.

Link to comment
Share on other sites

  • WHMCS CEO

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 months later...

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 2 weeks later...
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.

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