Jump to content

How to validate user session on custom page ?


Executable

Recommended Posts

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
}

 

Link to comment
Share on other sites

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
}

 

Link to comment
Share on other sites

  • 2 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