Jump to content

Share the login session on non-WHMCS pages?


zomex

Recommended Posts

Hello everyone,

 

I've researched this in the past but couldn't find any information. Is it possible to share the login session to non-WHMCS pages? By this I mean if someone is logged in to WHMCS and goes to a non-WHMCS page is it possible to pull the first name etc from the database?

 

Thanks,

Jack

Link to comment
Share on other sites

function user_get_id()
{
   $pagetitle = '';
   $pageicon = "";
   $breadcrumbnav = ''; 
   initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav);
   $sessionid = $_SESSION['uid'];
   return $sessionid;
}

 

Not sure if initialiseClientArea HAS to be called but this way works just fine. Returns null if no session is detected.

Link to comment
Share on other sites

function user_get_id()
{
   $pagetitle = '';
   $pageicon = "";
   $breadcrumbnav = ''; 
   initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav);
   $sessionid = $_SESSION['uid'];
   return $sessionid;
}

 

Not sure if initialiseClientArea HAS to be called but this way works just fine. Returns null if no session is detected.

 

Thanks very much for your reply.

 

I'm not too sure how/where to use this code. I'd appreciate it greatly if you could give me some tips.

 

Once again thanks for posting this!

Link to comment
Share on other sites

http://wiki.whmcs.com/Creating_Pages this would probably explain better than I can.

 

I have that function I posted in a seperate file called functions.php.

 

On the index.php page I make a reference to user_get_id() such as:

 

<?php
$sessionid = user_get_id();
if ($sessionid !='') {
echo('User is logged in.');
} else {
echo('User is not logged in.');
}
?>

 

Functions.php would look similar to this:

 

<?php
require("dbconnect.php");
require("includes/functions.php");
require("includes/clientareafunctions.php");
function user_get_id()
{
   $pagetitle = '';
   $pageicon = "";
   $breadcrumbnav = ''; 
   initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav);
   $sessionid = $_SESSION['uid'];
   return $sessionid;
}
?>

Edited by erix920
Link to comment
Share on other sites

http://wiki.whmcs.com/Creating_Pages this would probably explain better than I can.

 

I have that function I posted in a seperate file called functions.php.

 

On the index.php page I make a reference to user_get_id() such as:

 

<?php
$sessionid = user_get_id();
if ($sessionid !='') {
echo('User is logged in.');
} else {
echo('User is not logged in.');
}
?>

 

Functions.php would look similar to this:

 

<?php
require("dbconnect.php");
require("includes/functions.php");
require("includes/clientareafunctions.php");
function user_get_id()
{
   $pagetitle = '';
   $pageicon = "";
   $breadcrumbnav = ''; 
   initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav);
   $sessionid = $_SESSION['uid'];
   return $sessionid;
}
?>

 

Thanks very much for taking the time to reply.

 

I probably didn't word my thread too well (my writing is pretty bad :D ) but I'm looking for a way to do this on a non-WHMCS page for example my main website is made up of static HTML/CSS pages. Would this be possible? I'm guessing that it's not possible but until I find out I'm going to be keep researching :D

 

Thanks,

Jack

Link to comment
Share on other sites

  • 2 weeks later...
This should be the simplest way to check session outside of whmcs.

 

<?php
require("whmcs/dbconnect.php"); // You may have to change the path here

if ($_SESSION['uid']) {
echo "whmcs user logged in";
} else {
echo "whmcs user not yet login";
}
?>

 

Ronnie

 

Wow! Your code worked perfectly Ronnie, thanks very much. I've been looking for a way to do this since I started using WHMCS over a year ago.

 

Would it be possible to pull information from the database such as the clients first name?

 

Thanks very much.

Link to comment
Share on other sites

You can quote the user information by the session id

 

require("whmcs/dbconnect.php");

if ($_SESSION['uid']) {

$query="SELECT * FROM tblclients WHERE id='" .$_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 ($row['firstname'].' '.$row['lastname'].' | '.$row['email']);

} else {

echo "Please Login";
}

 

Ronnie

Link to comment
Share on other sites

Thanks so much for your help Ronnie! I've almost got this working perfectly for my needs thanks to your help. I have one last problem which I will be grateful if you can point me in the right direction.

 

Here's my (your) code:

 

<?php require("../clients/dbconnect.php");

if ($_SESSION['uid']) {

$query="SELECT * FROM tblclients WHERE id='" .$_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 "


<div id=\"navigation-secondary\">
<ul>

<li><a href=\"/clients/clientarea.php?action=details\" title=\"Welcome back!\">Welcome back ('.$row['firstname'].')</a></li>

<li><a href=\"/clients/clientarea.php\" title=\"Home\">Home</a></li>
<li><a href=\"/test/\" title=\"Test\">Test</a></li>
<li><a href=\"/clients/clientarea.php?action=details\" title=\"My Details\">My Details</a></li>
<li><a href=\"/clients/clientarea.php?action=products\" title=\"My Services\">My Services</a></li>
<li><a href=\"/clients/clientarea.php?action=domains\" title=\"My Domains\">My Domains</a></li>
<li><a href=\"/clients/clientarea.php?action=invoices\" title=\"My Invoices\">My Invoices</a></li>
<li><a href=\"/clients/supporttickets.php\" title=\"My Tickets\">My Tickets</a></li>
<li><a href=\"/clients/clientarea.php?action=emails\" title=\"My Emails\">My Emails</a></li>
<li><a href=\"/clients/affiliates.php\" title=\"Affiliates\">Affiliates</a></li>
<li><a href=\"/clients/logout.php\" title=\"Logout\" style=\"border: none;\">Logout</a></li>
</ul>
</div>



";

} 


?>

 

What I'm doing is displaying the WHMCS logged in menu on non-WHMCS pages. Since you're new code I have decided to add a new tab on the menu titled 'welcome back NAME'. As you can see I have an error on that line as I must not be calling the value correctly.

 

Here's the problem line (everything else works perfectly):

 

<li><a href=\"/clients/clientarea.php?action=details\" title=\"Welcome back!\">Welcome back [color="red"]('.$row['firstname'].')[/color]</a></li>

 

May I ask what the correct way to display the users name here would be?

 

Thanks very much!

Jack

Link to comment
Share on other sites

  • 3 months later...

Hi,

 

I am also trying to create an external login form for WHMCS... ...but it doesn't work...

 

here is my code... ..someone can tell me what is my error?

 

Thanks in advance!

 

<?php
require("client/dbconnect.php"); 

if ($_SESSION['uid']) {
echo "Connecté";
} else {
echo  "
<div id="login"> <a href="#" id="link" class="signin">Connexion</a>    <form class="drop">
         <label for="name">Adresse courriel :</label>
         <input type="text" name="email" class="required"/>
         <label for="password">Mot de passe :</label>
         <input type="password" name="password" />
         <p class="remember">
           <input type="checkbox" class="checkbox"/>
           Se souvenir de moi</p>
         <input type="submit" class="submit" value="Sign In" />
         <p><a href="#" class="tooltip">Oublié votre mot de passe?<span>Cliquez ici pour le réinitialiser!</span></a></p>
       </form>
     </div>
";

}  
?>

Link to comment
Share on other sites

Thanks so much for your help Ronnie! I've almost got this working perfectly for my needs thanks to your help. I have one last problem which I will be grateful if you can point me in the right direction.

 

Here's my (your) code:

 

<?php require("../clients/dbconnect.php");

if ($_SESSION['uid']) {

$query="SELECT * FROM tblclients WHERE id='" .$_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 "


<div id=\"navigation-secondary\">
<ul>

<li><a href=\"/clients/clientarea.php?action=details\" title=\"Welcome back!\">Welcome back ('.$row['firstname'].')</a></li>

<li><a href=\"/clients/clientarea.php\" title=\"Home\">Home</a></li>
<li><a href=\"/test/\" title=\"Test\">Test</a></li>
<li><a href=\"/clients/clientarea.php?action=details\" title=\"My Details\">My Details</a></li>
<li><a href=\"/clients/clientarea.php?action=products\" title=\"My Services\">My Services</a></li>
<li><a href=\"/clients/clientarea.php?action=domains\" title=\"My Domains\">My Domains</a></li>
<li><a href=\"/clients/clientarea.php?action=invoices\" title=\"My Invoices\">My Invoices</a></li>
<li><a href=\"/clients/supporttickets.php\" title=\"My Tickets\">My Tickets</a></li>
<li><a href=\"/clients/clientarea.php?action=emails\" title=\"My Emails\">My Emails</a></li>
<li><a href=\"/clients/affiliates.php\" title=\"Affiliates\">Affiliates</a></li>
<li><a href=\"/clients/logout.php\" title=\"Logout\" style=\"border: none;\">Logout</a></li>
</ul>
</div>



";

} 


?>

 

What I'm doing is displaying the WHMCS logged in menu on non-WHMCS pages. Since you're new code I have decided to add a new tab on the menu titled 'welcome back NAME'. As you can see I have an error on that line as I must not be calling the value correctly.

 

Here's the problem line (everything else works perfectly):

 

<li><a href=\"/clients/clientarea.php?action=details\" title=\"Welcome back!\">Welcome back [color="red"]('.$row['firstname'].')[/color]</a></li>

 

May I ask what the correct way to display the users name here would be?

 

Thanks very much!

Jack

 

The code you all are using is not safe and is vulnerable to SQL injection attack. You always want to sanitize any input provided by the user before passing it to MySQL. Cookie data is easily modified by an attacker. Add the following function to your code:

 

<?php
function sanitize($data)
{
// remove whitespaces (not a must though)
$data = trim($data); 

// apply stripslashes if magic_quotes_gpc is enabled
if(get_magic_quotes_gpc())
{
	$data = stripslashes($data);
}

// a mySQL connection is required before using this function
$data = mysql_real_escape_string($data);

return $data;
}
?>

 

I put it in a file called functions.php and include it in the header of all my pages:

 

  
<?php
require("functions.php");
?>

 

Then change your code to wrap the $_SESSION['uid'] in your query to be like: sanitize($_SESSION['uid'])

 

$query="SELECT * FROM tblclients WHERE id='" .sanitize($_SESSION['uid']). "'";

 

Not doing this can lead to all you customer data leaking out and possibly even your server compromised.

Link to comment
Share on other sites

Hi,

 

I am also trying to create an external login form for WHMCS... ...but it doesn't work...

 

here is my code... ..someone can tell me what is my error?

 

Thanks in advance!

 

<?php
require("client/dbconnect.php"); 

if ($_SESSION['uid']) {
echo "Connecté";
} else {
echo  "
<div id="login"> <a href="#" id="link" class="signin">Connexion</a>    <form class="drop">
         <label for="name">Adresse courriel :</label>
         <input type="text" name="email" class="required"/>
         <label for="password">Mot de passe :</label>
         <input type="password" name="password" />
         <p class="remember">
           <input type="checkbox" class="checkbox"/>
           Se souvenir de moi</p>
         <input type="submit" class="submit" value="Sign In" />
         <p><a href="#" class="tooltip">Oublié votre mot de passe?<span>Cliquez ici pour le réinitialiser!</span></a></p>
       </form>
     </div>
";

}  
?>

 

 

Try this and see if it works. If it doesn't let us know any error messages that pop up:

 

 

<?php
require("client/dbconnect.php"); 

if ($_SESSION['uid']) {
echo "Connecté";
} else {
echo  "
<div id=\"login\"> <a href=\"#\" id=\"link\" class=\"signin\">Connexion</a>    <form action=\"client/dologin.php\" method=\"post" class=\"drop\">
         <label for=\"username\">Adresse courriel :</label>
         <input type=\"text\" name=\"username\" class=\"required\"/>
         <label for=\"password\">Mot de passe :</label>
         <input type=\"password\" name=\"password\" />
         <p class=\"remember\">
           <input type=\"checkbox\" class=\"checkbox\"/ name=\"rememberme\">
           Se souvenir de moi</p>
         <input type=\"submit\" class=\"submit\" value=\"Login\" />
         <p><a href=\"#\" class=\"tooltip\">Oublié votre mot de passe?<span>Cliquez ici pour le réinitialiser!</span></a></p>
       </form>
     </div>
";

}  
?>

 

This is assuming your WHMCS install in under the folder "client"

Link to comment
Share on other sites

The code you all are using is not safe and is vulnerable to SQL injection attack. You always want to sanitize any input provided by the user before passing it to MySQL. Cookie data is easily modified by an attacker. Add the following function to your code:

 

<?php
function sanitize($data)
{
// remove whitespaces (not a must though)
$data = trim($data); 

// apply stripslashes if magic_quotes_gpc is enabled
if(get_magic_quotes_gpc())
{
	$data = stripslashes($data);
}

// a mySQL connection is required before using this function
$data = mysql_real_escape_string($data);

return $data;
}
?>

 

I put it in a file called functions.php and include it in the header of all my pages:

 

  
<?php
require("functions.php");
?>

 

Then change your code to wrap the $_SESSION['uid'] in your query to be like: sanitize($_SESSION['uid'])

 

$query="SELECT * FROM tblclients WHERE id='" .sanitize($_SESSION['uid']). "'";

 

Not doing this can lead to all you customer data leaking out and possibly even your server compromised.

 

Thanks very much my friend. I've correct the code and everything functions as before. I'm sending you a PM to show you the code just to be certain (I hope that's ok).

 

Thanks,

Jack

Link to comment
Share on other sites

Thanks very much my friend. I've correct the code and everything functions as before. I'm sending you a PM to show you the code just to be certain (I hope that's ok).

 

Thanks,

Jack

 

I don't mind at all ;) And I should say also that the sanitize function doesn't have to be in a separate file, it just makes the code a bit cleaner imo.

Link to comment
Share on other sites

  • 10 years later...

  

I wat session uid of whmcs display at orther my source

My code test.php

Quote

<?php
require_once 'configuration.php';
require_once 'includes/dbfunctions.php';
require_once 'includes/functions.php';
require_once 'includes/adminfunctions.php';
require_once 'includes/clientareafunctions.php';
session_start();
use WHMCS\Authentication\CurrentUser;
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
$query="SELECT * FROM tblclients WHERE id='" .sanitize($_SESSION['uid']). "'";
echo $_SESSION["uid"];

//Orther source
define('IN_SITE', true);
include_once('add_class.php');
include_once('add_menu.php');
include_once(FOLDER_MODULE.'/global_trangchu.php');
$giaodien_trangchu = new GiaoDienTrangChu();
$smarty->assign( 'giaodien_trangchu' , $giaodien_trangchu->giaodien_trangchu() );
$smarty->display('index.tpl');
?>

 

index.tpl file
 

Quote

 

........................

        {if $loggedin}
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <i class="fas fa-bell"></i>  <span class="badge up badge-info">{$clientAlerts|count}</span>
            </a>
            <ul class="dropdown-menu dropdown-scroll dropdown-tasks auto">
                <li class="dropdown-header">
                    <i class="fas fa-info-circle"></i> ({$clientAlerts|count}) {$LANG.notifications}
                </li>
                <li id="taskScroll">
                    <ul class="list-unstyled">
                        {foreach $clientAlerts as $alert}
                        <li>
                            <a class="text-{$alert->getSeverity()}" href="/{$alert->getLink()}">{$alert->getMessage()} {if $alert->getLinkText()} <button href="{$alert->getLink()}" class="btn btn-xs btn-{$alert->getSeverity()}">{$alert->getLinkText()}</button>{/if}</a>
                        </li>
                        {foreachelse}
                        <li>
                            <a href="javascript:;">{$LANG.notificationsnone}</a>
                        </li>
                        {/foreach}
                    </ul>
                </li>
            </ul>
        </li>
        {/if}       

........................

 

 

But session uid whmcs on test.php do not work

Please help me fix test.php

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