Web Hosting Talk







View Full Version : Session Variables in WHMCS


jgsketch
10-03-2007, 12:53 PM
Since my clients come to me already paid for hosting, I've managed to get with the other website and have setup session variables to be passed from their site to mine, so that customer will not have to re-enter all their personal information, the signup form will be prepopulated in WHMCS's signup page.

I have got it working on a test signup page as well as being able to echo data on my custom pages. But when I go and transfer the code into the actual signup page, the process no longer works. Very frustrating.

Is there any kind of session variable time out setting in WHMCS or in the code on any pages that could be preventing me from using them?

Here is a snippet of the signup page and the echo's I'm using:
<? session_start(); ?>
<tr><td width=120>
{$LANG.clientareafirstname}
</td><td>
<input type="text" name="firstname" size=30
value="<? echo $_SESSION['FirstName']; ?>">
*</td></tr>

Here is the sessions. I put this code on my front page index.php, the landing page from the site that is passing the data from.

<?

@session_start();
$_SESSION['RepID'] = $_REQUEST['RepID'];
$_SESSION['Company'] = $_REQUEST['Company'];
$_SESSION['FirstName'] = $_REQUEST['FirstName'];
$_SESSION['LastName'] = $_REQUEST['LastName'];
$_SESSION['Email'] = $_REQUEST['Email'];
$_SESSION['BillStreet1'] = $_REQUEST['BillStreet1'];
$_SESSION['BillStreet2'] = $_REQUEST['BillStreet2'];
$_SESSION['BillCity'] = $_REQUEST['BillCity'];
$_SESSION['BillState'] = $_REQUEST['BillState'];
$_SESSION['BillPostalCode'] = $_REQUEST['BillPostalCode'];
$_SESSION['WorkPhone'] = $_REQUEST['WorkPhone'];


?>

I've tried not useing the session_start tag on the order page, since WHMCS said sessions are already active within WHMCS. No change.

However, when I do add the session_start tag to the top of the encrypted order.php page in WHMCS, I can echo the data. Unfortunatly because it's an encrypted page, I get an error after the echoed data.

WHMCS says that is probably a problem with my code and that the sessions should have passed along just fine.

Could someone let me know if my code is wrong? I can't seem to figure this out. Thanks.

dean1012
10-03-2007, 02:24 PM
Is the old site and WHMCS both on the same server?

jgsketch
10-03-2007, 02:28 PM
Thanks for replying.

My site and WHMCS are on the same server. The site that is passing the data to me is on another server.

But I can still echo the data on my custom pages. So I know it works to a certain extent.

dean1012
10-03-2007, 02:33 PM
Ok, the reason I asked that is because initially I had my company site setup in the following fashion:

Site/forums/press - hostgator
WHMCS - trexhost

When it came time for me to integrate WHMCS with my main site, I needed to do something similiar. I needed to read the WHMCS session from my main site and get data like first name and if the person was logged in.

I was having trouble figuring this out and put in a ticket to Matt at WHMCS. He responded telling me that what I was attempting to do was impossible - or, at the least, if I found a way to do it that it would be terribly insecure.

I am a PHP programmer (as well as other languages) and nonetheless attempted various experiments on my own. Because sessions are stored server side and not client side, I was unable to get my main site to read the WHMCS session just as Matt had predicted.

In the end, I had to terminate my trexhost account and move WHMCS to hostgator. This fixed the issue.

I am not saying your issue is impossible as well but you probably won't find a good solution passing session data between two servers.

jgsketch
10-03-2007, 02:39 PM
Thank you.

I have the data passing to my website first, index.php. Then passing it on further to WHMCS. Both on the same server. Does it not matter that they are on the same server? As stated in you post above, you had your site on a different server but once moved, you were able to pass the data. This would be similar to my situation. The only difference is that I'm passing data 3 times.

From Server1 -> Server2(my site) -> Server2(WHMCS)

Just trying to understand. Thanks.

dean1012
10-03-2007, 02:43 PM
so to make sure I understand,

Server1 passes data to Server2 (index.php) then passes to WHMCS (also on server2)

I assume the visitor visits Server1 to initiate the process. Are you redirecting them to Server2 (index.php)?

jgsketch
10-03-2007, 02:54 PM
Correct.

Clients pay for hosting and other products and services on Server1(some company I partnered with). They then get redirected after paying to Server1(index.php my hosting site) to do the domain registration and account setup for hosting.

dean1012
10-03-2007, 03:01 PM
Hmm...

Ok, so here's a few more questions:

1) After the user is redirected to index.php on Server2, are you sure the session is set? I mean, can you do:

print_r($_SESSION);

and get the values you need?

2) If the answer to #1 is yes, are you redirecting the user from index.php to WHMCS or are you giving the user a link to click to proceed to WHMCS?

3) Is the user being sent directly to the WHMCS order page? Which step of the order process? Is it a different page instead?

jgsketch
10-03-2007, 03:15 PM
1) Yes I was able to echo on index.php as well as any pages that I created outside of WHCMS.

2) I'm giving the user a link to click on. This brings them to the step 1 of the order process.

3) The user is sent from index.php to (WHMCS) order.php?step=2&pid=1 (step2 of 5). They continue on through steps 3 and 4. Order.php?step=5&pid=1 (Step 5) is the singup page where the fields will be pre-populated with the session variables.

dean1012
10-04-2007, 04:34 PM
This is beyond me I can't think of why it is doing this.

Anyone else have a clue?

jgsketch
10-04-2007, 04:41 PM
I'm just going to have to have my clients enter the fields manually. WHMCS was not willing to build a custom page for me? :)

I did find out that where I was putting my echo code was wrong. I'm was not suppose to delete the {$clientsfirstname} tag out of the value="" field. So I tried putting it elsewhere in the value field while keeping the orginal tag. Still did not work.

jgsketch
10-04-2007, 06:19 PM
Just out of curiosity, if I can at least echo the data on my other pages, does that mean my php.ini is correct? Nothing would be stopping the echo on other pages due to wrong settings?

jgsketch
10-04-2007, 06:33 PM
Sorry should have posted my settings

session.auto_start----0
session.bug_compat_42----1
session.bug_compat_warn---1
session.cache_expire---180
session.cache_limiter----nocache
session.cookie_domain----
session.cookie_lifetime----0
session.cookie_path-----/
session.entropy_file------
session.entropy_length-----0
session.gc_divisor-----100
session.gc_maxlifetime----1440
session.gc_probability----1
session.name-----phpsessid
session.referer_check-----
session.save_handler-----files
session.save_path------N;/path
session.serialize_handler-----php
session.use_cookies-----1
session.use_only_cookies-----1
session.use_trans_sid-----0

jgsketch
10-06-2007, 11:06 PM
Solved. In case anyone runs across a similar problem. I spent many hours and found this works... {$smarty.session.something}.