PDA

View Full Version : Serve content based on Session Variable HELP


Heckie
12-17-2010, 07:25 AM
I am building a website for a client who sells heating components.

I am looking to serve slightly different content on the pages of my site depending on if people are one of 3 groups - consumer, landlord or installer.

On my home page - there are 3 tabs, each with its own 'more' button. (3 tabs / 3 more buttons).

What I would like to do is set a session variable (ContentType) to enable me to show the correct content for each group.

Then on each page I'm going to set up variables that use 'IF ContentType = x'

I would also like the session to be reset every time someone visits the home page.

Im thinking that I need to wrap each home page tab inside a form, but maybe theres a better way?

Jason Byrnes
12-17-2010, 09:36 AM
you would need to use if statements to choose which content to serve:

<?php if(isset($_SESSION['ContentType']) && $_SESSION['ContentType'] = "1") { ?>
show content for content type equals 1
<?php } ?>



you could use the following code to unset the session:
<?php if(isset($_SESSION['ContentType'])) unset($_SESSION['ContentType'])); ?>

Heckie
12-20-2010, 02:27 AM
Thanks Jason.

How do I set the session variables in the first place? On my home page - there are 3 tabs, each with its own 'more' button. (3 tabs / 3 more buttons).

Each click should set a session variable:

Consumer - 1
Housing Associations - 2
Installers - 3

Does each one need its own FORM?

Jason Byrnes
12-20-2010, 07:27 AM
each button would link to a page passing a querystring variable:
<a href=""page.php?ContentType=1">Consumer</a>
<a href=""page.php?ContentType=2">Housing Associations</a>
<a href=""page.php?ContentType=3">Installers</a>

the on page.php use the set session variable server behavior to set the session using the ContentType querystring.


First go to the bindings panel and click the plus button, select URL Variable and name it ContentType.


Then on the server behavior panel, click the plus button and select eCart -> General -> Set Session Variable. For the trigger, click the lightning bolt, and select the ContentType URL Variable, do the same for the value, and set the name to ContentType