Buenas necesito, que me orienten como hacer atravez de una funcion ,habilitar y deshabilitar, el link del menu, Login , nick (regusuario) , fin de session, en cada caso.. y en cada parte o session de la pagina, hasta ahora, se logra logearse y fin de session, lo que no encuentro es hacer que en caso de logear a un usuario , ejemplo en index.php salga login, y no salga el nick, y a su vez sale Fin de session, y en caso de Fin de session sale en index.php sale login, y Fin de Session, quiero deshabilitar en cada caso, Login en caso de que este logeado el usuario , y en caso de Fin de session entre index.php pero despues no salga Fin de Seccion...
Login Momentaneo
<?php
if (isset ($_POST['submit'] )){
$data_root = $_SERVER[DOCUMENT_ROOT];
include ($data_root . "/site/sec/funciones.php");
$nick = $_POST['nick'];
$password = $_POST['password'];
//CREACION DE VARIABALES - INICIO DE SESION
$sql = mysql_query("SELECT * FROM registro WHERE nick='$nick' AND password='$password'");
$login_check = mysql_num_rows($sql);
//CREACION DE SESION
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
session_register('id');
$_SESSION['id'] = $id;
$usuario = $row["nick"];
session_register('usuario');
$_SESSION['usuario'] = $usuario;
header("location: cuenta.php");
exit();
} // close while
} else {
print '<br /><br />No se pudo iniciar sesion, los datos no concuerdan <br /><br /><a href="login.php">Click aqui</a> para regresar a la pagina de inicio de sesion.';
exit();
}
}// close if post
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inicio de Sesion</title>
</head>
<body>
<table align="center" cellpadding="5">
<form action="login.php" method="post" enctype="multipart/form-data" name="logform" id="logform">
<tr>
<td width="46">Nick</td>
<td width="100"><input name="nick" type="nick" id="nick" size="14" maxlength="15"/></td>
</tr>
<tr>
<td>Clave</td>
<td><input name="password" type="password" id="password" size="14" maxlength="14" /></td>
</tr>
<tr>
<td><input name="submit" type="submit" value="Login" id="submit"/></td>
<td>Olvido su Clave</td>
</tr>
</form>
</table>
</body>
</html>
Logout redireccionando al index.php
<?php
session_start();
session_destroy();
if(!session_is_registered('id')){
$msg = "Se ha Finalizado la sesión";
} else {
$msg = "<h2>No se ha finalizado la sesión</h2>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fin de Sesion</title>
</head>
<body>
<?php print $msg; ?>
<script type="text/javascript">
location.href='http://localhost/site/index.php';
</script>
</body>
</html>
Cuenta.php
<?php
$data_root = $_SERVER[DOCUMENT_ROOT];
include ($data_root . "/site/sec/funciones.php");
if($pag!="") {
$plantilla = $pag;
}
if($_GET[pag]!="") {
$plantilla = $_GET[pag];
}
if($_POST[pag]!="") {
$plantilla = $_POST[pag];
}
if(!($plantilla)) {
$plantilla = "home";
}
?>
<?php
session_start();
$menu_links = "";
if (isset($_SESSION['id'])) {
$userid = $_SESSION['id'];
$usuario = $_SESSION['usuario'];
//CREACION DEL MENU AUTOMATICO
//MENU USUARIOS REGISTRADOS
$menu_links = '<a href="cuenta.php?id=' . $userid . '">' . $usuario . '</a> • <a href="logout.php">Fin Sesion</a>';
} else {
//MENU USUARIOS NO REGISTRADOS
$menu_links = '<a href="registro.php">Registrarse</a> • <a href="login.php">Inicio de Sesion</a>';
header("location: index.php");
exit();
}
?>
<div>|<a href="index.php"> Home </a>|<a href="index.php" >Novedades</a> |<a href="nosotros.php"> ¿Quiénes Somos? </a>|<a href="registro.php" target="_parent"> Regístrate |</a><a href="contactenos.php">Contáctanos</a>|<?php MENU
$menu_links2 = "";?><?php echo $menu_links; ?></div>MENU Login Logout y sus variables
Index.php
<?php
$data_root = $_SERVER[DOCUMENT_ROOT];
include ($data_root . "/site/sec/funciones.php");
if($pag!="") {
$plantilla = $pag;
}
if($_GET[pag]!="") {
$plantilla = $_GET[pag];
}
if($_POST[pag]!="") {
$plantilla = $_POST[pag];
}
if(!($plantilla)) {
$plantilla = "home";
}
?>
Html
<div> |<a href="index.php"> Home </a>|<a href="index.php" >Novedades</a> |<a href="nosotros.php"> ¿Quiénes Somos? </a>|<a href="registro.php" target="_parent"> Regístrate |</a><a href="contactenos.php">Contáctanos</a>|<a href="login.php">Login</a>|
<?php $menu_links2 = "";?>Menu Login y Logout
<a href="logout.php">Fin Sesion</a></div>Menu Login y Logout