Jump to content

Custom Login


Recommended Posts

Hi,

 

I am using a light box for my clients to login from the homepage of my website. The end user clicks "login" and the light box pops up displaying a login form. For now I have used the post action within the form

"post" action="http://www.yourdomain.com/whmcs/dologin.php"

 

which directs the end user to their account perfectly.

 

However I would like to know how to get a response from WHMCS so that if they were to go back to the homepage it would say their username and logout etc instead of "login" still. I think it is bad ux for them to have to log back in every time they navigate away from the WHMCS pages.

 

I would be grateful if anyone could show me how to do this? 8)

 

 

Thanks, Matt

Link to comment
Share on other sites

something like this maybe (assuming whmcs is installed into the "whmcs" directory)

 

<?php

if (isset($_SESSION['uid'])) {
 $adminid = 1; // ID of admin to execute API functions as (must have API access)
 include("whmcs/dbconnect.php");
 include("whmcs/includes/functions.php");
 $res = localAPI('getclientsdetails', array('clientid'=>$_SESSION['uid']), $adminid);
 if ($res['result'] == 'success') {
   $firstname = $res['firstname'];
   $lastname = $res['lastname'];
   $email = $res['email'];
   $loggedin = true;
 } else {
   $loggedin = false;
} else {
 $loggedin = false;
}

?>

<html>
<head>
<!-- header -->
</head>
<body>
<!-- Some body code here -->
<?php 
if ($loggedin) {
?>
Hello <?= $firstname; ?> <?= $lastname; ?>! <br />
<a href="whmcs/logout.php">Logout</a>
<?php
} else {
?>
<!-- Display login form here -->
<?php
}
?>

 

This is completely untested, and requires shorttags to be enabled in PHP to work, assuming I didnt make any mistakes.

Link to comment
Share on other sites

something like this maybe (assuming whmcs is installed into the "whmcs" directory)

 

<?php

if (isset($_SESSION['uid'])) {
 $adminid = 1; // ID of admin to execute API functions as (must have API access)
 include("whmcs/dbconnect.php");
 include("whmcs/includes/functions.php");
 $res = localAPI('getclientsdetails', array('clientid'=>$_SESSION['uid']), $adminid);
 if ($res['result'] == 'success') {
   $firstname = $res['firstname'];
   $lastname = $res['lastname'];
   $email = $res['email'];
   $loggedin = true;
 } else {
   $loggedin = false;
} else {
 $loggedin = false;
}

?>

<html>
<head>
<!-- header -->
</head>
<body>
<!-- Some body code here -->
<?php 
if ($loggedin) {
?>
Hello <?= $firstname; ?> <?= $lastname; ?>! <br />
<a href="whmcs/logout.php">Logout</a>
<?php
} else {
?>
<!-- Display login form here -->
<?php
}
?>

 

This is completely untested, and requires shorttags to be enabled in PHP to work, assuming I didnt make any mistakes.

 

Hi, thanks for your reply. I couldn't get it to work, is there another way of doing it rather than using the API?

Link to comment
Share on other sites

Nah, just use the built in sql helper functions for WHMCS. Since you're including the dbconnect.php file from WHMCS as I listed before, there will be no need to add your DB connection details as well.

 

Sorry to be a pain but because I'm not that familiar with php would you be able to show me how to accomplish this please?

Edited by LondonWebSolutions
Grammer
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