Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2009-09-16 00:16:00

crcool75
Member
Registered: 2009-09-16
Posts: 7

Assigning PHP Variables...

Hello,

I'm new to Flux, but really like what I see so far.  I have installed Flux into http://www.mysite.com/forum and need to pass variables over to Flux from mysite.  I've done this successfully by inserting the variables into the URL and then echoing them back in Flux's index.php, but after you leave index.php the variables are gone.  How do I permanently assign a variable?  I've tried the PHP function $_SESSION, but no go.

We're using X-Cart in our site's root directory and I'm allowing X-Cart member's only access the forum.  I want to pass the user's name from X-Cart to Flux.

Thanks.

Offline

#2 2009-09-16 09:22:33

Oldskool
Developer
From: Netherlands
Registered: 2008-12-28
Posts: 141
Website

Re: Assigning PHP Variables...

If you want to use variables globally (within multiple scripts), sessions should be the way to go. Make sure you add this block of code to each script you want to use the variables in:

<?php
if ( !session_id () ) {
    session_start ();
}
?>

You can set and call variables in the format $_SESSION['var_name']. There is plenty of documentation on sessions on the PHP website itself and countless boards and sites that should get you more familiar with it. Be careful to keep an eye on security with sensitive data though, putting them in session variables is usually not the best way to go.

Offline

#3 2009-09-17 02:28:58

crcool75
Member
Registered: 2009-09-16
Posts: 7

Re: Assigning PHP Variables...

Thank you very much, Oldskool...  BTW - Cool avatar, LOL, too many memories.

I've worked with PHP Sessions all day and understand what they do.  Basically what I'm trying to do is require our X-Cart members to log into X-Cart before they can even access FluxBB.  I then pass their $login variable to FluxBB via the URL link that becomes available to them.  Then I allow guests to do everything on FluxBB and want to pass the $login variable to the Guest's name when they post a new message.  Since the board requires them to be logged into X-Cart, I see no problem with this.

I used your code above, but there are just a few things I still don't understand.  PHP sessions seem to use a cookie and allow the customer to browse the BB on this cookie.  What about the cookie's expiration time?  I don't know how to check for this cookie on every page other than putting it in all PHP files?

This is the code I put in FluxBB's index.php:

<?php

// Custom Area
session_cache_expire(2);
session_start();
if ($_SESSION['loginname'] == '') {
$_SESSION['loginname'] = $_GET['loginname']; }
if ($_SESSION['loginname'] == '') {
header( 'Location: http://www.mysite.com/x-cart_login.php' ); }

?>

What I'm trying to do here is:

1.  Set the session's expiration time to 2 minutes (testing purposes).
2.  Check if $_SESSION['loginname'] has a value.
3.  If $_SESSION['loginname'] has no value then try to get it from the URL.
4.  If $_SESSION['loginname'] still has no value then redirect them to X-Cart's login page.

This logic seems it would work, but what if they bypass index.php?  What if a non-member bypasses the index.php?

I hope this isn't getting too complicated.  It seems I'm so close to achieving this, as if I can touch it, just can't grab it!

Offline

#4 2009-09-17 09:30:29

Oldskool
Developer
From: Netherlands
Registered: 2008-12-28
Posts: 141
Website

Re: Assigning PHP Variables...

crcool75 wrote:

I used your code above, but there are just a few things I still don't understand.  PHP sessions seem to use a cookie and allow the customer to browse the BB on this cookie.  What about the cookie's expiration time?  I don't know how to check for this cookie on every page other than putting it in all PHP files?

Well, session cookies are valid for as long as the browser is open. Once the browser is closed by the visitor, the session dies with it. And yes, you should have a session_start in all PHP files that need to check if the user is logged in. If you do not use session_start, you can not verify any $_SESSION variables.

crcool75 wrote:
<?php

// Custom Area
session_cache_expire(2);
session_start();
if ($_SESSION['loginname'] == '') {
$_SESSION['loginname'] = $_GET['loginname']; }
if ($_SESSION['loginname'] == '') {
header( 'Location: [url=http://www.mysite.com/x-cart_login.php]http://www.mysite.com/x-cart_login.php'[/url] ); }

?>

I would suggest to pass the login on the background instead of through a URL, because it is very unsafe and can be easily manipulated by the user to post under a false/different name. I am not familiar with X-Cart, but I would think that you should be able to extract the username from a variable in there?

Offline

#5 2009-09-18 14:11:21

crcool75
Member
Registered: 2009-09-16
Posts: 7

Re: Assigning PHP Variables...

Well, I've spent time with X-Cart trying to assign a session variable with no success.  X-Cart uses its own proprietary sessions called x_sessions which makes it even more difficult for me.  The bottom line here is X-Cart needs to create this session variable for Flux to read.  Without that I'm dead in the water.  I'm on X-Cart's forums for help on this now.

What I'm doing right now is disabling all options for guests, even registering.  When we add a new member to X-Cart (must be done by us), we add them to the Flux forum too.  Unfortunately they have to log in twice.  I wish I could create a custom login page that logged them into both sites at the same time. 

I've spent entirely too much time on this so far.  I have a lot of ideas floating around in my head and just haven't put them down on paper yet.  Thank you for all your help, Oldskool, as its allowed me to gain vital knowledge.  If you have any other suggestions, please feel free to post it.

Offline

Board footer

Powered by FluxBB 1.4.8