I am working on a university project, which is based on e-shopping. I tried this code to implement my result, this gives an error and does not work - I think there's a mistake with the code there.

This code is from my login header:

<?php 
        if($_GET('user_type')='Administrator')

        !isset($_SESSION['txt_username']) || !isset($_SESSION['txt_pwd'])){
            echo "<a href='login.php'>Log in</a>";                                          
        }else{
            echo $_SESSION['txt_username'];
            echo ' &nbsp; | &nbsp; <a href="logout.php"> Log Out</a>';
            } 
        ?>
有帮助吗?

解决方案

Try this, you had some syntax issues:

<?php 
 //you will need this before you do anything with $_SESSION
 session_start(); 

   if(isset($_GET['user_type']) && $_GET['user_type'] == 'Administrator'){

      if( !isset($_SESSION['txt_username']) || !isset($_SESSION['txt_pwd']) ){

            echo "<a href='login.php'>Log in</a>";                                          

      }else{

            echo $_SESSION['txt_username'];
            echo ' &nbsp; | &nbsp; <a href="logout.php"> Log Out</a>';

      }  
   }
?>

其他提示

Issue in line below

     if($_GET('user_type')='Administrator') 

Should be:

   if($_GET['user_type']=='Administrator')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top