Jump to content

Integration Code - Don't show Client Login if they are Logged in


davet

Recommended Posts

I know how to add the Client Login box to other pages outside of WHMCS but if the customer logs in and visits that page it still shows the Login box. Is there anyway to change this to a "Logout button" or a link to "Client Area" instead of showing the username and password form elements again?

 

If they're logged in it shoudn't really show the login box anymore... but instead maybe a logout link.

 

I understand this probably has something to do with the session but am not really sure how to accomplish this. Any ideas?

Link to comment
Share on other sites

As the integration code for pages outside whmcs is just a simple form, you can't have what you want without adding some extra code to the pages.. The easy way of doing this is by making custom pages inside the whmcs system so you can show what you want to the visitor.

Link to comment
Share on other sites

Well I'm trying to integrate it with Joomla as far as a wrapper is concerned so creating the extra pages within WHMCS is just not feasible. Any ideas as to the "extra" code I would need to add to my external pages to support this functionality?

Link to comment
Share on other sites

Try this:

 

 <?php
         echo date("l F jS Y ");
         require("dbconnect.php");
         require("includes/functions.php");
         require("init.php");
         if ($_SESSION['loggedinstatus']=="true") {
         echo("<hr/><strong>Welcome Back</strong><br>");
         echo "<strong>{$clientsdetails[firstname]}</strong>" ;
         echo " ";
         echo "<strong>{$clientsdetails[lastname]}</strong><br><br>" ;
         echo ("<br><br><form method=post action=logout.php><input type=submit class=submitbutton value=Logout /></form>");
         }
     else 
         echo "<form method="post" action="dologin.php?goto=clientarea">
                     Email Address: <input type="text" name="username" size="50"><br>
                     Password: <input type="password" name="password" size="20"><br>
                     <input type="submit" value="Login">
                     </form>";

       ?>

Link to comment
Share on other sites

The only real problem I see with what you have posted (not tried it out) is that you do echo "stuff here" but then you include a lot of double quotes within (in the html) without escaping them.

 

Your best bet would be to do echo 'stuff here' and to put the html in double quotes, or vice versa. Echo " and then use ' for the HTML. That is unless you feel like going in and escaping every double quote.

 

<?php
         echo date("l F jS Y ");
         require("dbconnect.php");
         require("includes/functions.php");
         require("init.php");
         if ($_SESSION['loggedinstatus']=="true") {
         echo("<hr/><strong>Welcome Back</strong><br>");
         echo "<strong>{$clientsdetails[firstname]}</strong>" ;
         echo " ";
         echo "<strong>{$clientsdetails[lastname]}</strong><br><br>" ;
         echo ("<br><br><form method=post action=logout.php><input type=submit class=submitbutton value=Logout /></form>");
         }
     else 
         echo '<form method="post" action="dologin.php?goto=clientarea">
                     Email Address: <input type="text" name="username" size="50"><br>
                     Password: <input type="password" name="password" size="20"><br>
                     <input type="submit" value="Login">
                     </form>';

       ?>

 

That might work a tad better, that is if the script works at all (I've not tried it)

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
doesn't work for me :-/

When I posted that I couldn't have read it properly and I posted code to go into a template.

For a php file the MikeDVB's code is OK except change this line

if ($_SESSION['loggedinstatus']=="true") {

to

if ($_SESSION['uid']) {

and don't forget to close the if/else statement with the missing } (it's supposed to be just above ?>)

Link to comment
Share on other sites

again, i think this would work for the template file

 

this is what i got now

<?php
         echo date("l F jS Y ");
         require("dbconnect.php");
         require("includes/functions.php");
         require("init.php");
         if ($_SESSION['uid']) {
         echo("<hr/><strong>Welcome Back</strong><br>". $_SESSION('uid'));

         echo "<strong>{$clientsdetails[firstname]}</strong>" ;
         echo " ";
         echo "<strong>{$clientsdetails[lastname]}</strong><br><br>" ;
         echo ("<br><br><form method=post action=logout.php><input type=submit class=submitbutton value=Logout /></form>");
         }
     else 
         echo '<form method="post" action="dologin.php?goto=clientarea">
                     Email Address: <input type="text" name="username" size="50"><br>
                     Password: <input type="password" name="password" size="20"><br>
                     <input type="submit" value="Login">
                     </form>';


       ?>

 

 

and it only prints out welcome back

Link to comment
Share on other sites

The $clientsdetails[firstname] may not have worked because the 3 requires where in brackets with double quotes.

This should solve your problems

 

<?php
echo date("l F jS Y ");
require 'dbconnect.php';
require 'includes/functions.php';
require 'init.php';
if ($_SESSION['uid']) {
 $result = mysql_query("SELECT firstname,lastname FROM tblclients WHERE id=" . $_SESSION['uid'] . "");
 $data = mysql_fetch_array ($result);
 echo "<hr/><strong>Welcome Back</strong><br>";
 echo "<strong>{$data['firstname']}</strong> " ;
 echo "<strong>{$data['lastname']}</strong><br><br>" ;
 echo "<br><br><form method=post action=logout.php><input type=submit class=submitbutton value=Logout /></form>";

} else  {
 echo '<form method="post" action="dologin.php?goto=clientarea">
                     Email Address: <input type="text" name="username" size="50"><br>
                     Password: <input type="password" name="password" size="20"><br>
                     <input type="submit" value="Login">
                     </form>';
}
?>

Link to comment
Share on other sites

again, i think this would work for the template file

 

this is what i got now

<?php
         echo date("l F jS Y ");
         require("dbconnect.php");
         require("includes/functions.php");
         require("init.php");
         if ($_SESSION['uid']) {
         echo("<hr/><strong>Welcome Back</strong><br>". $_SESSION('uid'));

         echo "<strong>{$clientsdetails[firstname]}</strong>" ;
         echo " ";
         echo "<strong>{$clientsdetails[lastname]}</strong><br><br>" ;
         echo ("<br><br><form method=post action=logout.php><input type=submit class=submitbutton value=Logout /></form>");
         }
     else 
         echo '<form method="post" action="dologin.php?goto=clientarea">
                     Email Address: <input type="text" name="username" size="50"><br>
                     Password: <input type="password" name="password" size="20"><br>
                     <input type="submit" value="Login">
                     </form>';


       ?>

 

 

and it only prints out welcome back

 

You left out

          
}
     else 
{

}
?>

 

 

After I changed my pages and upgraded to 3.7.2 that code stopped working for me also, you can try this one:

<?php
         include("dbconnect.php");
         include("includes/functions.php");
         include("init.php");
         if ($_SESSION['loggedinstatus']=="true") {
         echo("<hr/><strong>Welcome Back</strong><br>");
         echo("<strong>{$clientsdetails[firstname]}</strong>");
         echo(" ");
         echo("<strong>{$clientsdetails[lastname]}</strong><br><br>");
         echo ("<br><br><form method="post" action="logout.php"><input type="submit" class="submitbutton" value="Logout" /></form>");
         } else  {
         echo '<form method="post" action="dologin.php?goto=clientarea">
                     Email Address: <input type="text" name="username" size="50"><br>
                     Password: <input type="password" name="password" size="20"><br>
                     <input type="submit" value="Login">
               </form>';
}
?>

Edited by BAJI26
Link to comment
Share on other sites

  • 4 weeks later...
hey folks. Stand-alone this works great. When integrated with another site, I think the current Session is not allowing me to see the WHMCS session. Any suggestions on why this isn't working or getting it to work with a site which already has an active session? thanks

 

I found that too in the newest Whmcs version.

Create this file (loginfile.php):

 

<?php
         session_start();
         echo $_SESSION["uid"];
         include("dbconnect.php");
         include("includes/functions.php");
         include("init.php");
         if (!empty($GLOBALS['clientsdetails']['id']))  {

         PUT SOMETHING HERE

         } else {

         PUT SOMETHING HERE

         }

?>

 

Add this in the page you want the login to appear:

 


<?php
$userid = file_get_contents("loginfile.php");
if ($userid) {

         PUT SOMETHING HERE

    } else {

         PUT SOMETHING HERE  

         }
?>

Link to comment
Share on other sites

Heya Baji26, very much appreciate the response and code. I was experimenting with something very similar earlier. Those tests, along with tests using this code, always result in the $userid executing true. I suspected the software I was trying to integrate with, so I created just PHP files with the code above and had the same result.

 

:( Always true. This works ok for you? Thanks for the help!

Link to comment
Share on other sites

Yes mine work perfectly... There is probably a better and much more efficient way but this is what I have working.

 

I'm no coder but this is what I hacked together and it work.

 

Add this to your header... <?php include('db_connection.php'); ?>

 

Include this in the page where you want the login form to apppear.... <?php require('login_on_html.php'); ?>

 

You probably know the rest...

 

login_getuserid.php:

 

<?php

session_start();
echo $_SESSION["uid"];

?>

 

 

login_header.php:

 

 

<?php
$userid = file_get_contents("login_getuserid.php");
if ($userid) {

         echo ("<font size= 4px><font color= 86CE50><strong>Welcome Back</strong></font></font><br>");
         echo ("<strong>{$clientsdetails[firstname]}</strong>");
         echo (" ");
         echo ("<strong>{$clientsdetails[lastname]}</strong><br><br>") ;
         echo ("<br><form method=post action=logout.php><input type=submit class=submitbutton value=Logout /></form>");
    } else {
         echo(ADD YOUR CODE HERE);
         }
       ?>

 

login_on_html.php:

 

<?php

         include("init.php");
         if (!empty($GLOBALS['clientsdetails']['id']))  {
         echo("<hr/><font size= 4px><font color= 86CE50><strong>Welcome Back</strong></font></font><br>");
         echo ("<br><br><form method=\"post\" action=\"logout.php\"><input type=\"submit\" class=\"submitbutton\" value=\"Logout\" /></form>");
         echo(ADD YOUR MORE CODE HERE);
         } else {
         echo(ADD YOUR CODE HERE);

         }

?> 

Edited by BAJI26
Link to comment
Share on other sites

Add this to your header... <?php include('db_connection.php'); ?> ---> on which page?

 

Actually, i dont understand the logic after reading the code why is login_header.php linked to login_on_html.php:?

 

i do see that login_header.php has a link to login_getuserid.php.

 

oh and where to create this 3 files in? args~ i think most likely i will need a step by step instructions :(

 

This is something funny, BAJI26 hope you can explain how this thing works...

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