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.
You could simply check if the session variable "mm_username" is set. If set they're logged in. If not show other message (welcome guest).

i2-Services, Inc. Wrote:
You could simply check if the session variable "mm_username" is set. If set they're logged in. If not show other message (welcome guest).


Thank you for your help. So, I would just have something like this inserted into the page:

PHP Code:
<?php
if ($_SESSION[mm_username] != null){
   echo
"Welcome $_SESSION[mm_username]!";
   include(
"my_script.php");
}
if (
$_SESSION[mm_username] == null){
   echo
"Welcome Guest. Please click <html link code to a login page>here</code> to sign in."
}
?>


Correct?

Try:

Code:
<?php
if ($_SESSION[mm_username]){
   echo "Welcome $_SESSION[mm_username]!";
   include("my_script.php");
}

else {
   echo "Welcome Guest. Please click <html link code to a login page>here</code> to sign in."
}
?>


Or you could use Welcome $_SESSION[mm_name]

Which would show the logged in users name, not username.

I somewhat having it working. I had to include "session_start();" to get it to work, though.

Code:
<?php
session_start();
if ($_SESSION[mm_username]){
$test = rand(1,5);
   echo "Welcome $_SESSION[mm_username]!<br>
<a href =\"test.php\">refresh</a><br>$test";
}else{
   echo "Welcome Guest. Please click <html link code to a login page>here</code> to sign in.";
}
?>


When I log out of my test user account and then refresh the page that has this code, the variable still seems to be set and it does not execute the path of code to the "Welcome Guest..." message. I know it is not a cached version of the page, because it generates new random numbers. It seems to only follow the "else" path if I have cleared my cache. I also tried...

Code:
if ($_SESSION[mm_username] != null){

...but I had the same result.

Any ideas?

Michael,

Which version of PHP MM are you currently using?

you could try checking the session var of:

$_SESSION[email_address]
I'm using version 2.3, but it seems to work perfectly with the $_SESSION[email_address]. Thanks. Smile

Michael Wrote:
I'm using version 2.3, but it seems to work perfectly with the $_SESSION[email_address]. Thanks. Smile


Ok - you could also just FYI:

$_SESSION[mm_logged_in]

with v2.3+

That's good to know. (I apologize if I ask too many questions.) Thanks again; this software has been very helpful!
We love questions. You kidding? Smile
Pages: 1 2
Reference URL's