domain@exitra.com.my Posted March 4, 2013 Share Posted March 4, 2013 I want to show client name in wordpress when his is logged in to the WHMCS. What i did is i create a login/ register in wordpress home page and when this client have logged in show his name instead. Below are something i have try out. i create the WHMCS and as subdomain in my wordpress root file. In my wordpress header.php i entered the following: <?php require_once(ABSPATH. 'whmcs/dbconnect.php'); require_once(ABSPATH. 'whmcs/includes/functions.php'); require_once(ABSPATH. 'whmcs/includes/clientareafunctions.php'); if ($_SESSION['uid']) { $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_SESSION['uid']); $data = mysql_fetch_array($result); $clientname = $data[0]; echo $clientname; } else { echo 'Not logged in'; } ?> But these coding doesn't work, instead i received a 'Down for Maintenance' message in wordpress. Anyone have idea what gone wrong here? 0 Quote Link to comment Share on other sites More sharing options...
sufi Posted March 5, 2013 Share Posted March 5, 2013 Create a file (say wp-custom.php) in your WHMCS root folder. Start session in that file: <?php session_start(); Now in your wp theme file, use following code(use your whmcs db credentials): require_once "PATH-TO-WHMCS/wp-custom.php"; $db_host = "DB-HOST"; $db_user = "DB-USER"; $db_pass = "DB-USER-PASSWORD"; $db_name = "DB-NAME"; $con = mysql_connect($db_host, $db_user, $db_pass); $db = mysql_select_db($db_name, $con); if ($_SESSION['uid']) { $name1 = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_SESSION['uid']); $name2 = mysql_query("SELECT lastname FROM tblclients WHERE id=".(int)$_SESSION['uid']); $data1 = mysql_fetch_array($name1); $data2 = mysql_fetch_array($name2); $firstname = $data1[0]; $lastname = $data2[0]; $content = '<div> ' . $firstname . ' ' . $lastname . '<br/>'; echo $content; } else{ echo "Not logged in!"; } mysql_close($con); You can put this code in function.php and call from anywhere of the theme. 0 Quote Link to comment Share on other sites More sharing options...
BreakingBad Posted May 7, 2013 Share Posted May 7, 2013 Great ! I try many many, too many things ! For a loooooooooooooong time :-( I can't used include and opendir because my WordPress and my whmcs are on the same shared server in 2 seperate cpanel account. So i try your method, supress the call to php file with the start_session and add it on the top ogf the WordPress header code like that: <?php session_start(); $db_host = "localhost"; ............ Now i can access to the database, but he say that i'm not loggin. I'm not developpeur but i understand that you check that with session, and i believe the start_session must be on the whmcs side in the php file.... If i'm right, a solution for me were to use cookie for checking login/logout ? I understand that it is possible to use cookie method on a domain (WordPress) and his subdomain (my whmcs) If anybody can help me before i'm going crazy, or do the job for a little fee... Sorry for my bad English ! 0 Quote Link to comment Share on other sites More sharing options...
sufi Posted May 7, 2013 Share Posted May 7, 2013 If WHMCS and WP are in two different IPs, session will not work, and will require COOKIE. Great ! I try many many, too many things ! For a loooooooooooooong time :-( I can't used include and opendir because my WordPress and my whmcs are on the same shared server in 2 seperate cpanel account. So i try your method, supress the call to php file with the start_session and add it on the top ogf the WordPress header code like that: <?php session_start(); $db_host = "localhost"; ............ Now i can access to the database, but he say that i'm not loggin. I'm not developpeur but i understand that you check that with session, and i believe the start_session must be on the whmcs side in the php file.... If i'm right, a solution for me were to use cookie for checking login/logout ? I understand that it is possible to use cookie method on a domain (WordPress) and his subdomain (my whmcs) If anybody can help me before i'm going crazy, or do the job for a little fee... Sorry for my bad English ! 0 Quote Link to comment Share on other sites More sharing options...
sufi Posted May 7, 2013 Share Posted May 7, 2013 Here is the solution: On very top of your header.tpl file (from whmcs templates), add following code: {if $loggedin} {php} $value = $_SESSION['uid']; setcookie("whmcsuid", $value, 0, "/", ".domain.com"); //you should not use www {/php} {/if} Now in wordpress, in your theme's functions.php, add: $db_host = "DB-HOST"; /*you need to put IP of your whmcs cPanel, also you will have to add your wp cpanel IP in the remote MySQL option of your WHMCS cpanel. */ $db_user = "DB-USER"; $db_pass = "DB-USER-PASSWORD"; $db_name = "DB-NAME"; $con = mysql_connect($db_host, $db_user, $db_pass); $db = mysql_select_db($db_name, $con); if ($_COOKIE['whmcsuid']) { $name1 = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_COOKIE['whmcsuid']); $name2 = mysql_query("SELECT lastname FROM tblclients WHERE id=".(int)$_COOKIE['whmcsuid']); $data1 = mysql_fetch_array($name1); $data2 = mysql_fetch_array($name2); $firstname = $data1[0]; $lastname = $data2[0]; $content = '<div> ' . $firstname . ' ' . $lastname . '<br/>'; echo $content; } else{ echo "Not logged in!"; } mysql_close($con); 0 Quote Link to comment Share on other sites More sharing options...
BreakingBad Posted May 7, 2013 Share Posted May 7, 2013 Thank you a lot sufi for your answer ! I'm soo pleased to see that i'm not alone ^^ I will try that right now and come back. 0 Quote Link to comment Share on other sites More sharing options...
BreakingBad Posted May 7, 2013 Share Posted May 7, 2013 I had a heart attack when i see my name in my header ^^ It did not work correctly if i put the code in my header WordPress (break my layout) But if i put it in a widget area in my header it work's great ! Is it a safe way to achieve this ? I mean shall i put in place a login option for publique area in my WHMCS ? A friend said that i must replace any of session uid i can found in WordPress ?!? Again thank you a lot for your help ! Don't know how to thank you ! 0 Quote Link to comment Share on other sites More sharing options...
BreakingBad Posted May 7, 2013 Share Posted May 7, 2013 i speak to quickly, i saw my name one time, since i purge the cache he said i'm not loggin... Maybe my friend were right, but i don't understand on what side i must do that... 0 Quote Link to comment Share on other sites More sharing options...
sufi Posted May 8, 2013 Share Posted May 8, 2013 Well, the div was not closed, so it was breaking your layout. Following code will fix it: $db_host = "DB-HOST"; /*you need to put IP of your whmcs cPanel, also you will have to add your wp cpanel IP in the remote MySQL option of your WHMCS cpanel. */ $db_user = "DB-USER"; $db_pass = "DB-USER-PASSWORD"; $db_name = "DB-NAME"; $con = mysql_connect($db_host, $db_user, $db_pass); $db = mysql_select_db($db_name, $con); if ($_COOKIE['whmcsuid']) { $name1 = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_COOKIE['whmcsuid']); $name2 = mysql_query("SELECT lastname FROM tblclients WHERE id=".(int)$_COOKIE['whmcsuid']); $data1 = mysql_fetch_array($name1); $data2 = mysql_fetch_array($name2); $firstname = $data1[0]; $lastname = $data2[0]; $content = '<div> ' . $firstname . ' ' . $lastname . '<br/></div>'; echo $content; } else{ echo "Not logged in!"; } mysql_close($con); Without session or cookie, you won't be able to check either an user is logged in or not, and it's not a security leak. However you should do a check when user is logged out and destroy cookie, or it will show your information on your wp site, as long as you don't close the browser. 0 Quote Link to comment Share on other sites More sharing options...
BreakingBad Posted May 8, 2013 Share Posted May 8, 2013 It look like it work better in the functions php than in the widget... But it still break the layout in function.php However, in widget area it's fine, just in the right place ^^ I desactivate WordPress cache plugin and whmcs cache plugin for my Template. sometimes it show my username correctly. But it clearly won't work has it should. I have a WordPress/whmcs integration with my WordPress header and footer on whmcs, maybe the problem is link. By the way has a system/network engineer i have bypass many of my dev skill... Please PM me if we can make a deal or go further with more reply ^^ or remote assistance... Thank you a lot for your patience ! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.