Jump to content

loggedin() outside WHMCS


steelaz

Recommended Posts

Sorry.. Save the first part as isloggedin.php

 

Then change "pathto/whmcs/isloggedin.php" in the second part to the correct path..

 

Yes.. that is what i did. I'm using WHMCS4, I don't know if that might help

 

Code in http://seahosting.net/yourside.php

<?php
include('clients/isloggedin.php');
if ($isloggedin){ echo "logged in to whmcs"; }
?>

Link to comment
Share on other sites

treme[Z];108676']rl]

<?php
include('clients/isloggedin.php');
if ($isloggedin){ echo "logged in to whmcs"; }
?>

 

try

<?php
include('home/public_html/yourUSERname/clients/isloggedin.php');
if ($isloggedin){ echo "logged in to whmcs"; }
?>

And make sure you are logged in when accessing that page (client side) if your not logged in you would obviously get a blank page.

Link to comment
Share on other sites

treme[Z];108778']I got it working and now implemented on my website. 8)

 

Thanks for all the help. :-)

 

BTW: How do I make it welcome back $firstname ?

 

<?php
require("dbconnect.php");
if ($_SESSION['uid']) {
$isloggedin = 'true';

// off the top of my head I can't recall if the session stores user info other than the ID. So otherwise you'd have to query the database here. Use WHERE id = $_SESSION['uid']

}
?>

 

You can check what session info there is with:

<pre>
{php}print_r($_SESSION);{/php}
</pre>

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...
  • 1 year later...
Try this:

 

something.php (located in the WHMCS dir

<?php
require("dbconnect.php");
if ($_SESSION['uid']) {
$isloggedin = 'true';
}
?>

 

yoursite.php

<?php
include('pathto/whmcs/isloggedin.php');
if ($isloggedin){ echo "logged in to whmcs"; }
?>

 

 

Thanks for this. This actually works :D

 

Based on this I have made improvements to your code to make it more fuller and css tag friendly. I also moved the IF conditional statement into the whmcs folder. Anyway here it is:

 

something.php (located in the WHMCS dir

<?php
require("dbconnect.php");
if ($_SESSION['uid']) {
$result = mysql_query("SELECT firstname FROM tblclients WHERE id='".$_SESSION['uid']."' LIMIT 1;");
   while($row = mysql_fetch_array($result))
       echo "<p id='login'>".$_LANG['welcomeback'].', '.$row['firstname'].' | <a href="/whmcs/clientarea.php"><strong>'.$_LANG['clientareanavdetails'].'</strong></a> | <a href="/whmcs/logout.php"><strong>'.$_LANG['logouttitle'].'</strong></a></p>';
}
else{
   echo "<p id='login'>".$_LANG['please'].' <a href="/whmcs/clientarea.php" title="Login"><bold>'.$_LANG['loginbutton'].'</bold></a> '.$_LANG['or'].' <a href="/whmcs/register.php" title="Register"><bold>'.$_LANG['clientregistertitle'].'</bold></a></p>';
}
?>

 

 

yoursite.php (any php file outside whmcs folder)

<?php
include('pathto/whmcs/something.php');
?>

Link to comment
Share on other sites

Does this trick still work?

 

I am using whmcs_v431 and $_SESSION['uid'] is always empty even when I am logged in.

 

Thanks.

 

Mugoma,

hostyetu.com

 

I am using Version 4.3.1 and it is working fine. Are you using relative or absolute paths when you call the login_status.php using the php include method?

 

I discovered that this solution only works if you use relative paths instead of absolute paths.

Link to comment
Share on other sites

Hi.

 

I have also tried relative path but still $_SESSION['uid'] doesn't have any values.

 

But I could be doing it wrongly. This is what I have done:

1. I have service/isloggedin.php with the content:

<?php

require("dbconnect.php");

//echo $_SESSION['uid']." - _SESSION['uid']";

if ($_SESSION['uid']) {

$isloggedin = 'true';

}

?>

 

2. Then in my header.php I have:

<?php

include('service/isloggedin.php');

//echo $isloggedin." - isloggedin";

if ( $isloggedin ) {

?> Welcome,

<?php echo $clientsdetails['firstname'] } ?>

 

 

Both echo $_SESSION['uid'] and echo $isloggedin shows nothing even when logged in.

 

What could I be doing wrong? Please assist.

 

Thanks.

 

Mugoma.

Link to comment
Share on other sites

Try copying and pasting my code exactly as shown (but update the paths and filenames where necessary).

 

I think your problem might be caused by having the IF statement on the wrong side. All IF statements should be in the isloggedin.php file. There should be no IF statements in the header.php file.

Link to comment
Share on other sites

This works fine in mine, but blows up the rest of the page as I also have announcements being displayed on the same page. The two requires for the dbconnect file are to blame (one for each include), but if I kill either call that include fails. Using "mysql_close();" does nothing, as I believe the connection is persistent.

 

Love to use this, but unless I can puzzle out how to get them both to play nice, I can't.

Suggestions welcome. ;)

 

[EDIT]

Got it. Removed the dbconnect call from the included announcements file, and it uses the connection already established earlier in the page for the login switch.

Link to comment
Share on other sites

Hi.

 

Most likely there could be a problem with my setup but I haven't managed to figure out source of problem. E.g. in service/isloggedin.php if I just put:

 

<?php

require("dbconnect.php");

echo $_SESSION['uid']." - _SESSION['uid']";

?>

 

The $_SESSION['uid'] shows nothing, whether I am logged in or not. Should't it give 'true' or 'false'?

 

So obviously the complete version will have $isloggedin not set.

 

Do I need to put session_start(); somewhere to get a value from $_SESSION['uid']?

 

Since most people have reported the method working for them I will assume my setup could be the issue. I will be very grateful for any clue.

 

Thanks.

 

Mugoma.

 

Try copying and pasting my code exactly as shown (but update the paths and filenames where necessary).

 

I think your problem might be caused by having the IF statement on the wrong side. All IF statements should be in the isloggedin.php file. There should be no IF statements in the header.php file.

Link to comment
Share on other sites

Hello.

 

I finally figured it out. It was a very stupid omission.

 

The reason for $_SESSION['uid'] being empty was that I was accessing WHMCS login via www. while the main website I was accessing without www. That made all the difference! Could not figure it out till a few hours ago.

 

Thanks WHMCS Support for that!

 

Mugoma.

 

 

 

 

Hi.

 

Just in case this could be a hint. When I do print_r ($_SESSION); I get:

 

Array

(

[adminloggedinstatus] => true

[adminid] => 1

[adminpw] => fe591de2067a827ffd2da33f59e80697

)

Link to comment
Share on other sites

Hello,

 

I'm trying to login into whmc from joomla and i need to know it the user has been logged in in order to remove the login form if the user is logged in.

 

For this I followed the instructions you guys kindly shared.

 

I have in /home/website/public_html/client/isin.php (the WHMCS install folder)

 

<?php
require("dbconnect.php");
if ($_SESSION['uid']) {
$isloggedin = 'true';
}
?>

 

In the /home/website/public_html/modules/mod_login/tmpl/default.php (the joomla login module)

 

<?php
include("home/atom-hosting/public_html/client/isin.php");
if ($isloggedin == FALSE){ 
?>

<form method="post" action="https://website.com/client/dologin.php">
<input id="modlgn_username" type="text" name="username" value="email" onclick="this.value=''" class="username" />
<input id="modlgn_passwd" type="password" name="password" value="password" onclick="this.value=''"class="password" />
<input type="submit" name="Submit"  class="submit" value="Login" />
<div style="border:#000000; padding:0 6px 0 0; float:right;">	
<a href="https://website.com/client/pwreset.php">Forgot your password?</a></div>
<input type="hidden" name="task" value="ulogin" />
</form>

<?php } ?>

 

I get an error that says the file can't be opened

 

Warning: require_once(home/website/public_html/client/isin.php) [function.require-once]: failed to open stream: No such file or directory in /home/website/public_html/client/default.php on line 5

 

Fatal error: require_once() [function.require]: Failed opening required 'home/website/public_html/client/isin.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/website/public_html/client/default.php on line 5

 

The path is correct, the file has proper permissions , I don't know what else to do.

 

Thanks

Edited by bacterie
Link to comment
Share on other sites

Does the home directory not need a pre-pended slash?

include("home/atom-hosting/public_html/client/isin.php");

 

Should be:

include("/home/atom-hosting/public_html/client/isin.php");

 

Also on that note your line of code that includes the database should be an absolute path as I believe it will look from the directory you are calling the include from (if its not calling from the same directory).

require("dbconnect.php");

 

As well "session_start();" may be required in the isin.php file unless you have php setup to do this automatically.

 

And also this is a small issue but assigning a variable 'true' is setting the variable as a string and not the value of true. Remove the quotes and you can use less memory as well as have 2 less characters to type.

Link to comment
Share on other sites

Does the home directory not need a pre-pended slash?

include("home/atom-hosting/public_html/client/isin.php");

 

Should be:

include("/home/atom-hosting/public_html/client/isin.php");

 

Also on that note your line of code that includes the database should be an absolute path as I believe it will look from the directory you are calling the include from (if its not calling from the same directory).

require("dbconnect.php");

 

As well "session_start();" may be required in the isin.php file unless you have php setup to do this automatically.

 

And also this is a small issue but assigning a variable 'true' is setting the variable as a string and not the value of true. Remove the quotes and you can use less memory as well as have 2 less characters to type.

 

Hello,

 

If I write the include like this include("/home/atom-hosting/public_html/client/isin.php"); i get a message that says:

 

Down for Maintenance

An upgrade is currently in progress... Please come back soon...

 

The isin.php is in the same directory as the dbconnect.php file.

 

Thanks

Link to comment
Share on other sites

  • 1 month later...
Hello,

 

If I write the include like this include("/home/atom-hosting/public_html/client/isin.php"); i get a message that says:

 

Down for Maintenance

An upgrade is currently in progress... Please come back soon...

 

The isin.php is in the same directory as the dbconnect.php file.

 

Thanks

 

yeah, im having the same issue with the "Down for Maintenance

An upgrade is currently in progress... Please come back soon..." error. I know I must be having a brain fart and missing something simple.

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