Executable Posted March 14, 2019 Share Posted March 14, 2019 I would to know if it's possible to check user session into a custom page with php ? The custom page is situated on the same server and is in the whmcs folder. I need it to secure the page. Thank you for any reply 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted March 20, 2019 Share Posted March 20, 2019 Refer to Creating Pages. You don't need all the variables listed in the example but just the main class and... $ca->requireLogin(); // Forces visitors to login Or... if ($ca->isLoggedIn()) { // You are logged } else { // Not logged, exit } 0 Quote Link to comment Share on other sites More sharing options...
Executable Posted March 20, 2019 Author Share Posted March 20, 2019 Thank you for the answer. I found a workaround with the following code : if(isset($_POST['email']) and isset($_POST['password'])){ $conn = new mysqli("HOST", "USER", "PASS", "DATABASE"); if($stmt = $conn->prepare("SELECT `id` FROM `tblclients` WHERE `email` = ? AND `password` = ?")) { $stmt->bind_param("ss", $_POST['email'], $_POST['password']); $stmt->execute(); $result = $stmt->get_result(); while($row = $result->fetch_assoc()) { $id_user = $row['id']; } $stmt->close(); } $conn->close(); } if(isset($id_user) and !empty($id_user)){ //LOGGED IN }else{ //WRONG CREDENTIALS } 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 21, 2019 Share Posted March 21, 2019 Why are you doing it that way on a custom page? You should have access to capsule and other WHMCS items if you do the page as described on their creating custom pages page. 0 Quote Link to comment Share on other sites More sharing options...
Executable Posted March 22, 2019 Author Share Posted March 22, 2019 Thanks for the answer, I managed to use it. I would like to know what does the line $ca->initPage(); And my final page looks like : use WHMCS\ClientArea; use WHMCS\Database\Capsule; require 'init.php'; $ca = new ClientArea(); //$ca->initPage(); // What does this line do ? if(isset($_POST['email']) and isset($_POST['password']) and $ca->isLoggedIn()){ $conn = new mysqli("HOST", "USER", "PASSWORD", "DATABASE"); if($stmt = $conn->prepare("SELECT `id` FROM `tblclients` WHERE `email` = ? AND `password` = ?")) { $stmt->bind_param("ss", $_POST['email'], $_POST['password']); $stmt->execute(); $result = $stmt->get_result(); while($row = $result->fetch_assoc()) { $id_user = $row['id']; } $stmt->close(); } $conn->close(); }else{ header("Location: ../../../index.php"); } if(isset($id_user) and !empty($id_user) and isset($_POST['service_id']) and $ca->isLoggedIn()){ //Logged in }else{ //Not logged } 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted March 22, 2019 Share Posted March 22, 2019 It runs any autoloaders, sets other items, gives access to WHMCS objects for example, and sets up smarty at least a quick guess from the name of the function. 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'); ?> 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 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.