1

I don´t know if this is possible, but im trying to make a session if statement or something, like if the session name is "Simon" it will print a specific text, if the session name is not "Simon" it will do nothing.

This is part of my code and it work:

Part of the user login page:

$_SESSION['user'] = $row;

Part of the page i need the code on, now i just use it to print out the name of the person logged in:

   session_start();
   if(empty($_SESSION['user']))
   {
    header("Location: index.php");
    die("Redirecting to index.php");
   }

   echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8');
1
  • Are you talking about session name or session value?? Commented Sep 7, 2013 at 13:36

2 Answers 2

3
if(isset($_SESSION['user']['username'])){

  if($_SESSION['user']['username'] == "simon"){
   echo "Specific text here";
   }
}

For printing the name of the person logged in

if(isset($_SESSION['user']['username'])){
    echo "Welcome". $_SESSION['user']['username'];
    }
Sign up to request clarification or add additional context in comments.

1 Comment

You are welcome but a better advice is to first Google everything
-1
if(S_SESSION['user']=='Simon')
{
     echo "Your text";
}

you can type like this

1 Comment

if it does than, use $row['user'].. instead of simon

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.