zomex Posted February 2, 2011 Share Posted February 2, 2011 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 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted February 4, 2011 Author Share Posted February 4, 2011 Does anyone know if this is possible? Thanks. Jack 0 Quote Link to comment Share on other sites More sharing options...
arctic-ice-cool Posted February 5, 2011 Share Posted February 5, 2011 Desperately waiting for any ideas/examples of this too! 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted February 9, 2011 Author Share Posted February 9, 2011 I'm not sure if this is allowed but I'd like to consider this message a bump to hear from others Jack 0 Quote Link to comment Share on other sites More sharing options...
erix920 Posted February 9, 2011 Share Posted February 9, 2011 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. 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted February 9, 2011 Author Share Posted February 9, 2011 erix920 said: 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! 0 Quote Link to comment Share on other sites More sharing options...
erix920 Posted February 9, 2011 Share Posted February 9, 2011 (edited) 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 February 9, 2011 by erix920 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted February 15, 2011 Author Share Posted February 15, 2011 erix920 said: 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 ) 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 Thanks, Jack 0 Quote Link to comment Share on other sites More sharing options...
DannyTurner Posted February 28, 2011 Share Posted February 28, 2011 I would liketo know how to do this too 0 Quote Link to comment Share on other sites More sharing options...
nextinspire Posted February 28, 2011 Share Posted February 28, 2011 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 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted February 28, 2011 Author Share Posted February 28, 2011 nextinspire said: 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. 0 Quote Link to comment Share on other sites More sharing options...
nextinspire Posted March 1, 2011 Share Posted March 1, 2011 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 0 Quote Link to comment Share on other sites More sharing options...
Kristy Posted March 1, 2011 Share Posted March 1, 2011 Just wanted to thank Ronnie! This is going to be helpful 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted March 1, 2011 Author Share Posted March 1, 2011 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 0 Quote Link to comment Share on other sites More sharing options...
nextinspire Posted March 1, 2011 Share Posted March 1, 2011 Incorrect syntax. Should be like this: <li><a href=\"/clients/clientarea.php?action=details\" title=\"Welcome back!\">Welcome back".($row['firstname'])."</a></li> Ronnie 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted March 1, 2011 Author Share Posted March 1, 2011 Thanks very much Ronnie! Everything is now working perfectly. Jack 0 Quote Link to comment Share on other sites More sharing options...
Bonjour! Posted June 13, 2011 Share Posted June 13, 2011 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> "; } ?> 0 Quote Link to comment Share on other sites More sharing options...
microbolt Posted June 15, 2011 Share Posted June 15, 2011 zomex said: 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. 0 Quote Link to comment Share on other sites More sharing options...
microbolt Posted June 15, 2011 Share Posted June 15, 2011 Bonjour! said: 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" 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted June 15, 2011 Author Share Posted June 15, 2011 microbolt said: 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 0 Quote Link to comment Share on other sites More sharing options...
microbolt Posted June 15, 2011 Share Posted June 15, 2011 zomex said: 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. 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted June 15, 2011 Author Share Posted June 15, 2011 Thanks Yeah I agree, luckly I recently added a include at the top of every page for this purpose. It would take me a couple of hours otherwise. 0 Quote Link to comment Share on other sites More sharing options...
itdungpt Posted September 4, 2021 Share Posted September 4, 2021 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'); ?> Expand 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} ........................ Expand But session uid whmcs on test.php do not work Please help me fix test.php 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.