0

hello dear friends
i would like to show a text (message ) only if users is login (connect)
i use this code but i have a error

<?php
    if ($_SESSION['MM_Username'])
    empty {
    echo "<h4>please log in before adding to BASKET</h4>";
    }
    ?>
3
Contributors
4
Replies
28
Views
3 Years
Discussion Span
Last Post by chrisschristou
1

empty is a function to check the state of a variable.

you can use it as such:

<?php
 if (empty($_SESSION['MM_Username']))
   {
     echo ("<h4>please log in before adding to BASKET</h4>");
   }
</php>

see: http://php.net/manual/en/function.empty.php

however, most people use isset() instead of empty, as it checks for a variable being NULL as well.

<?php
  if (!isset($_SESSION['MM_Username']))
    {
      //do stuff
    }
</php>

see: http://www.php.net/manual/en/function.isset.php

notice the ! before the function? that means NOT, so the line reads "if variable $_SESSION['MM_Username'] is NOT set then do stuff".

good luck,

Ryan

Edited by ryantroop

0

thank you dear the first code work fine thank you again.
and i would like again cause i have 4 menu in ul li "login, create account, my acount and log out " i would like to hide login and create acount when users is connected and show when he connect hide log out and my account when he is not connected.
i can show with same up code nut how to hide ??

0

okay so in the body section where you put the create account, login, logout option, put the the code below:

<?php
  if (!isset($_SESSION['MM_Username']))
    {
      echo "<a href='login.php'>login</a><br><a href='signup.php'>create account</a>";
    }
  else
    {
    echo "<button style='width:300px; height:50px;' onClick=\"location.href='./signout.php'\">Sign out</button>";

    }
</php>

this should work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.