Jump to content

Login from website PHP code not working


Recommended Posts

Okay I'm have an issue with my website looking to see if the user is logged in when browsing site.

 

I have tired lots of ways.

 

Lets say my WHMCS is in /home/username/subdomains/whmcsfolder/

and website is in /home/username/public_html/

 

I have tired to do this many ways but does not work if I put this in my WHMCS folder it works fine but in my public_html it does not seem to wanna work?

 

when in web folder it just shows the login box even if already login!!

 

<?php 	

require("/home/username/path/to/whmcs/dbconnect.php");


if ($_SESSION['uid']) {

   $query="SELECT * FROM tblclients WHERE id='" .$_SESSION['uid'] . "'";

   $result = mysql_query($query) or die(mysql_error());
   if($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

     $clientsdetails['firstname']=$row['firstname'];
     $clientsdetails['lastname']=$row['lastname'];
     $clientsdetails['email']=$row['email'];

   }

   echo "

<ul>
<li>Welcome back  ".($row['firstname']). " ". ($row['lastname']). "!</li>
<li><a href=\"https://domain.com/clientarea.php\" title=\"My Dashboard\">My Dashboard</a></li>
<li><a href=\"https://domain.com/clientarea.php?action=changepw\" title=\"Change Password\">Change Password</a></li>
<li><a href=\"https://domain.com\" title=\"Logout\" style=\"border: none;\">Logout</a></li>
</ul>


   ";

} else {
 echo 									'<form method="post" action="https://domain.com/dologin.php">
									<fieldset style="margin: 5px;">
									<legend><li class="nav-header">Login</li></legend>
									<input type="hidden" name="token" value="<Taken Ouy>" />
									<label for="username">Email Address:</label>
									<input type="text" id="username" name="username" /><br />
									<label for="password">Password:</label>
									<input type="password" name="password" id="password" /><br />
									<button type="submit" class="btn btn-success">Login</button></form>';

Link to comment
Share on other sites

  • 2 months later...

Hello,

 

dbconnect.php was replaced by init.php (assuming you're running WHMCS v5.2) recently so it could be that that's causing the issues. So replace:

 

require("/home/username/path/to/whmcs/dbconnect.php");

 

with:

 

require("/home/username/path/to/whmcs/init.php");

 

Also these scripts only work if they use the same URL structure as your WHMCS. e.g if your system URL is:

 

http://www.domain.com/whmcs/

 

and you have the script installed at:

 

http://www.domain.com/index.php

 

As your WHMCS system URL uses www. you have to access the PHP page using www. for the session to be shared. You can use .htaccess to ensure that visitors are always redirected to whichever you prefer (this is also very good for SEO).

 

Jack

Link to comment
Share on other sites

I would suggest putting a small check script on the whmcs install root (aka : checklogin.php), which does the include and then returns data based on if the user is logged in or not, then on the page you wish for that data to be displayed, use jQuery/AJAX request to pull the data. This way, no matter what URL you are calling from, it will work. Extra data such as name, etc can be returned as a json encoded string along with a boolean whether the user is logged in or not. Since the call is made using AJAX, it uses the users session data to validate login.

 

To show/hide the login box, you can still use jQuery's element.show() / element.hide() , and you can set values on elements in the page using element.html(value) , etc.

 

This is useful if you wish to display/hide stuff based on whether the user is logged in or not (aka, a My Account menu item, logout link, etc).

Edited by microvb
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