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>";
    }
    ?>

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

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 ??

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.