hi all i want to do is hide links when the user is not login in.
i thought i could do it this way but it gave me a error

<?php 
if $_SESSION['MM_Username'] isset {
echo 'members area'; // i would put a link here
} 
else 
{

   echo ' ';
}
?>

but i gave me a error

Parse error: parse error, expecting `'('' in C:\wamp\www\mywigan\content.php on line 123

please can some one show me how to hide links if a user is not login in, and show them when the user is login in


thanks alot

hi all i want to do is hide links when the user is not login in.
i thought i could do it this way but it gave me a error

<?php 
if $_SESSION['MM_Username'] isset {
echo 'members area';
} 
else 
{

   echo ' ';
}
?>

but i gave me a error

Parse error: parse error, expecting `'('' in C:\wamp\www\mywigan\content.php on line 123

please can some one show me how to hide links if a user is not login in, and show them when the user is login in


thanks alot

put like this.

if($_SESSION['user_id']!=' ')
{
//put your link here.
}

one last question.

how would i show link depending on the users level.

e.g.

in the dater base the a have a coloum called level and them admin level is 9 and the users level is 1 .

how would i show a links to the admin pannel only to the users with the level 9.

thanks for you help:icon_cheesygrin:

if($_SESSION['user_id']==1)
  {

      //put user links here.

      }
 if($_SESSION['user_id']==1)
  {

      //put admin links here.

      }
if($_SESSION['user_id']==1)
  {

      //put user links here.

      }
 if($_SESSION['user_id']==1)
  {

      //put admin links here.

      }

thanks

i am getting this notice on my page

Notice: Undefined index: MM_Username in C:\wamp\www\mywigan\content.php on line 136
<?php
if($_SESSION['MM_Username'])
{  
	echo '	          <div id="CollapsiblePanel2" class="CollapsiblePanel">
                    <div class="CollapsiblePanelTab" tabindex="0">
                      <h1>Members pages</h1>
                    </div>
		            <div class="CollapsiblePanelContent">
                      
</a><a href="/mywigan/user/index.php">Memebers area</a> <br />
 </a><a href="/mywigan/user/private_messages/inbox.php">Private messages</a>
 <br />
 </a><a href="/mywigan/user/profile.php">Profile</a>
 <br />
 </a><a href="/mywigan/user/Competitions.php">Competitions</a>
</a></pre> <br />';
if($_SESSION['MM_UserGroup'] == 9)
{
 echo '</a><a href="/mywigan/admin/index.php">Admin Pannel</a>';
}

 echo '</div>';
		            
					}
?>

mm_username is the session i set at login but i only get these when the user is loged out so there is not session set

what have i do wrong

Member Avatar for diafol

1. Have session_start() at the top of every page straight after the '<?php' bit - before the DTD.
2. Use

if(isset($_SESSION['level'])){
   switch($_SESSION['level']){
      case 1:
         ...do something...
         break;
      case 2:
         ...do something...
         break;
      case 3:
         ...do something...
         break;
      case 4:
         ...do something...
         break;
   }
}else{
  ...do if not set...
}

Alternatively you could use multiple elseifs.

1. Have session_start() at the top of every page straight after the '<?php' bit - before the DTD.
2. Use

if(isset($_SESSION['level'])){
   switch($_SESSION['level']){
      case 1:
         ...do something...
         break;
      case 2:
         ...do something...
         break;
      case 3:
         ...do something...
         break;
      case 4:
         ...do something...
         break;
   }
}else{
  ...do if not set...
}

Alternatively you could use multiple elseifs.

thanks

but i can't get this to work what am i doing wrong here

<?php 
if(isset($_SESSION['MM_Username'])){
   switch($_SESSION['MM_UserGroup']){
      case 1:
         echo '<div id="CollapsiblePanel2" class="CollapsiblePanel">
                    <div class="CollapsiblePanelTab" tabindex="0">
                      <h1>Members pages</h1>
                    </div>
		            <div class="CollapsiblePanelContent">
                      
</a><a href="/mywigan/user/index.php">Memebers area</a> <br />
 </a><a href="/mywigan/user/private_messages/inbox.php">Private messages</a>
 <br />
 </a><a href="/mywigan/user/profile.php">Profile</a>
 <br />
 </a><a href="/mywigan/user/Competitions.php">Competitions</a>
</a></pre> <br />'
if($_SESSION['MM_UserGroup'] == 9)
{
 echo '</a><a href="/mywigan/admin/index.php">Admin Pannel</a>';
}
         break;
		 }else{
  echo ' ';
}

?>

buit i get this error

Parse error: parse error in C:\wamp\www\mywigan\login\index.php on line 248

what am i doing wrong

thanks

but i can't get this to work what am i doing wrong here

<?php 
if(isset($_SESSION['MM_Username'])){
   switch($_SESSION['MM_UserGroup']){
      case 1:
         echo '<div id="CollapsiblePanel2" class="CollapsiblePanel">
                    <div class="CollapsiblePanelTab" tabindex="0">
                      <h1>Members pages</h1>
                    </div>
		            <div class="CollapsiblePanelContent">
                      
</a><a href="/mywigan/user/index.php">Memebers area</a> <br />
 </a><a href="/mywigan/user/private_messages/inbox.php">Private messages</a>
 <br />
 </a><a href="/mywigan/user/profile.php">Profile</a>
 <br />
 </a><a href="/mywigan/user/Competitions.php">Competitions</a>
</a></pre> <br />'
if($_SESSION['MM_UserGroup'] == 9)
{
 echo '</a><a href="/mywigan/admin/index.php">Admin Pannel</a>';
}
         break;
		 }else{
  echo ' ';
}

?>

buit i get this error

Parse error: parse error in C:\wamp\www\mywigan\login\index.php on line 248

what am i doing wrong

The correct switch()/case: structure is

switch($var) {
    case 1:
    //do something
    break;
    case 2:
    //do something else
    break;
}

What you did was this:

switch($var) {
    case 1:
    //do something
    if($othervar)
    //do something
    break;
}

Change it to this:

switch($_SESSION['level']) {
    case 9:
        // show admin links
    break;
    case 1:
        // show user links (remember ending ";"... you don't have one in your code).
    break;
    default:
        // show guest links
}

Or, you could remove the "break;" if you wanted the admin, for instance, to also see the user links, or the users to also see the guest links.
How it works is that PHP goes thru the cases, and jumps into the code once it finds a case that's true. After that, it will process all the code until it comes to the end of the code block or a break; statement (whichever comes first). So, place your admin "case" at the top of the list, and you don't really need the if(isset($_SESSION['level'])){} , since it will only show what comes after the "default:" special case.

thank alot i will have a look at that now

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.