Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 登录时隐藏登录链接_Php_Mysql_Dreamweaver - Fatal编程技术网

Php 登录时隐藏登录链接

Php 登录时隐藏登录链接,php,mysql,dreamweaver,Php,Mysql,Dreamweaver,我的网站欢迎页面有一个登录链接和一个注销链接。我想知道如何仅在用户登录时显示注销链接,反之亦然 index.php代码: <?php require_once('Connections/PAPCon.php'); ?> <?php //initialize the session if (!isset($_SESSION)) { session_start(); } // ** Logout the current user. ** $logoutAction = $_S

我的网站欢迎页面有一个登录链接和一个注销链接。我想知道如何仅在用户登录时显示注销链接,反之亦然

index.php代码:

<?php require_once('Connections/PAPCon.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);

  $logoutGoTo = "login.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_PAPCon, $PAPCon);
$query_Users = "SELECT * FROM tbl_utilizadores";
$Users = mysql_query($query_Users, $PAPCon) or die(mysql_error());
$row_Users = mysql_fetch_assoc($Users);
$totalRows_Users = mysql_num_rows($Users);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>RelPro</title>
<link rel="stylesheet" type="text/css" media="screen" href="style.css" />
<style type="text/css">
#container #intro #pageHeader h1 {
    font-size: 4em;
}
</style>
</head>
<body>

<div id="container">
    <div id="intro">
      <div id="pageHeader" style="padding: 20px 0 0 50px;">
            <h1>RelPro</h1><h2>&nbsp;</h2>
            <h2><span>by: M&aacute;rio Hon&oacute;rio 12&ordm;PI N&ordm;6</span></h2>
        <h2><div style="position: absolute; left: 944px; top: 152px; height: 100px;"><img src="Logo PAP 2.png" alt="" width="230" height="187" /></div></h2>
        </div>

        <div id="preamble">
            <h3><span>Acerca da RelPro</span></h3>
            <p class="p1">Este website foi criado no &acirc;mbito do Curso Profissional de T&eacute;cnico de Gest&atilde;o de Equipamentos Inform&aacute;ticos de forma a avaliar toda a aprendizagem realizada. Foi concebido de forma a facilitar o acesso a relat&oacute;rios de projectos de final de curso de v&aacute;rias &aacute;reas a todos os interessados. &Eacute; um website de f&aacute;cil acesso, simples design e produzido em linguagem PHP, MySQL e HTML.</p>
        </div>
    </div>

    <div id="supportingText"></div>
    <div id="footer"></div>

    <div id="linkList">
        <div id="linkList2">
            <div id="lselect">
                <h3 class="select"><span>Sec&ccedil;&otilde;es:</span></h3>
                <ul>
                    <li>RelPro</li>
                    <li><a href="relatorios.php">Relat&oacute;rios</a></li>
                    <li><a href="admin.php">Admin</a></li>
                    <li><a href="contactos.php">Contactos</a></li>
                    <li><a href="login.php">Login</a></li>
                    <li><a href="<?php echo $logoutAction ?>">Log out</a></li>
                </ul>
      </div></div>
  </div>

</div>
</body>
</html>
<?php
mysql_free_result($Users);
?>
下面是部分菜单的图片,其中的链接是:


隐藏或禁用都可以。

根据会话显示它

if($_SESSION['MM_Username'])
{
?>
<li><a href="<?php echo $logoutAction ?>">Log out</a></li>
<?php
}else
{
?>
<li><a href="login.php">Login</a></li>
<?php
}

您可以通过检查会话变量是否已设置来显示它。仅一个会话变量的示例:

if(isset($_SESSION['MM_Username']))
    echo '<li><a href="' . $logoutAction . '">Log out</a></li>';
else
    echo '<li><a href="login.php">Login</a></li>';
不要使用MySQL驱动程序,因为它已被弃用。改用mysqlprofected

在这里可以有效地使用a

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

session_start();
session_destroy(); // comment this out if it gives you trouble

// Comment this out to test and using your own method of user check.
$_SESSION['MM_Username'] = "John";

$login = "<li><a href=\"login.php\">Login</a></li>";
$logout = "<li><a href=\"$logoutAction\">Log out</a></li>";

$check_login = isset($_SESSION['MM_Username']) ? $logout : $login;
与:

兼顾两种行为。 当然,你需要做一些调整,就位置而言。 参考资料:


经过一些研究和一些尝试和失败的尝试,这里是我用一些插件来做这件事的最后代码:

<?php
        $loginlink = "index.php";
        if (isset($_SESSION['MM_Username'])){
        echo "Hello " . $_SESSION['MM_Username'];
        echo "<br/><a href='".$logoutAction."'>Logout</a>";
        }else{
        echo "<a href='".$loginlink."'>Login</a>";}
?>
它对我有用,也许它可以帮助其他人。感谢@Richard Reiber,他的代码是我的跳转起点


和平,Slaxer13

如果会话包含有效用户,则将显示样式更改为无。。o_ODreamWeaver生成了非常糟糕的数据库接口代码。你真的应该尽快用更强大的东西来取代它。更好的是,选择一个适合你的风格和需要的。这些将在您使用的编辑器中工作,它们只是PHP。我尝试过,但没有工作。只是在链接之间出现了一条线,其他什么都没有
<ul>
    <li>RelPro</li>
    <li><a href="relatorios.php">Relat&oacute;rios</a></li>
    <li><a href="admin.php">Admin</a></li>
    <li><a href="contactos.php">Contactos</a></li>

    <?php echo $check_login; ?>

</ul>
<?php
        $loginlink = "index.php";
        if (isset($_SESSION['MM_Username'])){
        echo "Hello " . $_SESSION['MM_Username'];
        echo "<br/><a href='".$logoutAction."'>Logout</a>";
        }else{
        echo "<a href='".$loginlink."'>Login</a>";}
?>