i2-Services, Inc. Forums

Full Version: How To Tip: PHP Code to show HTML / Link based on assigned group
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This may be of use for those of you who want to show HTML within the control panel or protected pages when using the mod_rewrite option.

You can display links / html based on a group the user belongs to.

PHP Code:
{php}

if (
preg_match("/,1,/i", "$_SESSION[mm_lists]")) {

   echo "<a href=\"http://www.domain.com/members/page_name.html\">Link Text Here</a>";
}

{/
php}


The above code would show a link if the logged in user belonged to group # 1.

This example could also be used to do many different things w/ custom fields you setup.

if i wanted to use this to show to group 2, would i just change this part?
if (preg_match("/,2,/i", "$_SESSION[mm_lists]")) {
You got it.
I tried doing it for multiple groups (groups 1, 2, and 3), but it didn't work....:

if (preg_match("/,1,2,3,/i", "$_SESSION[mm_lists]")) {

is there a way?
I'm suggesting this w/out first testing it:

Code:
if (preg_match("/,1,/i", "$_SESSION[mm_lists]") | preg_match("/,2,/i", "$_SESSION[mm_lists]")) {

   // do something
}

Just tested it, should work fine. Here is my test:

Code:
<?php

session_start();

$_SESSION[mm_lists] = ",1,3,4,";

if (preg_match("/,1,/i", "$_SESSION[mm_lists]") | preg_match("/,5,/i", "$_SESSION[mm_lists]")) {

   echo "I am FOUND!";

}

else {

echo "i'm not in the session mm_lists value";

}

?>

For being part of all make the | in the code above a &&

i2-Services, Inc. Wrote:
For being part of all make the | in the code above a &&


Could the logon page provide a popup list of subscription areas to which the user is entitled, with the default being the last visited?

Eg the user subscribed to product1, product2, product3 and should be redirected to the product selected from a list with the choice made when last logging in always being the default.

When coming down to things like this a pre-built application is hard to work this way. This is pretty much considered a "custom feature" that would need to written for your purpose.
Group "0" is the free/basic usergroup, correct?

Can this idea be applied to public pages? Let say, I have a page that I do not want it to demand that its visitors sign in. However, I want code to run (e.g. "Welcome Guest", "You are not signed in", or a php include) when they are not signed in, but other code (e.g. "Welcome, username", hide the "You are not signed in" message, or a different php include) when they are signed in. Can this be done without require the visitor to sign in?
Pages: 1 2
Reference URL's