Login sin usar base de datos

Estoy haciendo una pagina que lleva login y password bueno para resumir la pregunta, lo que pasa es que en la base de datos no tiene nada sobre usuario ni password asi que lo que hice fue que hice es que en la paghina de index ahy mismo le di valores a usuario y password mira y tengo que manjer seciones y no me sale
<?php
session_start();
$usuario = "webmaster";
$password= "123456";
if ($_POST['user'] =="webmaster" && $_POST['password'] =="123456") {
$_SESSION['login'] = true;
$_SESSION['user'] = 'webmaster';
header ("Location: consultar.php");
}
?>
Ok luego pasa a consulta otra cosa en consulta no se como poner para que no entre si no esta login me podrias ayudar

1 Respuesta

Respuesta
1
funciones.php
---------------------------------------------
<?php
function check($usuario, $clave){
  return ($usuario == "webmaster" && $clave == "123456");
}
function logged(){
  if(check($_SESSION[usuario],$_SESSION[clave]){
    return true;
  }else{
    if(isset($_POST[usuario]) && isset($_POST[clave])){
      $_SESSION = $_POST;
      return check($_SESSION[usuario],$_SESSION[clave]);
    }else{
      echo '<form action="consultar.php" method="post"><input type="text" name="usuario" value="Usuario" /><input type="password" name="clave" /><input type="submit" value="Enviar" /></form>';
      return false;
    }
  }
}
?>
---------------------------------------------------
consultar.php
---------------------
<?php
require_once('./funciones.php');
echo '
<html>
<body>
';
if(logged()){
   //codigo de la pagina a la que solo se accede logueado
}
echo '
</body>
</html>
';
?>
------------------------------------------------
Espero que te sirva ;) (espero que no haya fallos, pero no lo he podido probar ;) ))
No he entendido esa funcion va dentro de index o en una pagina aprte y solo hago el llamado ademas al tratar de poner en consulta.php
Te agradeceria si puedes explicar un poquito mas disculpa las molestias pero es que nunca he trabajado asi que si fuera que ese usuario estubiera en la base de datos fuera todo facil pero como lo tuve que asignar es mas dificil te explico las coneciones de las paginas on asi
1- index.php ahy debe hacer login
2- si el login se da va a consultar.php
3- pero si no me he logiado y trato de entrar directo a consultar.php debe enviarme a index.php.
4- debo poder borrar las variables de secion
5- esa funcion que me diste debe estar en un apagina distinta y solo debo hacer el llamado require_once("./funcion.php");
6- es aparte de la funcion donde imprimes es para maneja rel login en todas las paginas es asi porque no entiendo si ya tengo el formularion en index.php
<table width="366" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#787878">
<tr>
<td width="358" height="121" valign="middle" bgcolor="#FFFFFF">
<form action="index.php" method="post">
<table width="358" height="126" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" bordercolor="#787878">
<tr bgcolor="#2872ae">
<td height="18" colspan="3">
<div align="center" class="Estilo4 Estilo4 Estilo10 Estilo3 Estilo1">PERSONAL DE BIBLIOTECA</div>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="25" height="36"> </td>
<td width="150" class="Estilo5 Estilo10">Usuario:</td>
<td width="183"><input name="user" type="text" id="user" size="20" maxlength="20" /></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="36"> </td>
<td class="Estilo5 Estilo10">Password:</td>
<td><input type="password" name="password" size="20" maxlength="20" /></td>
</tr>
<tr >
<td colspan="2">
<div align="center">
          <input name="entrar2" type="reset" id="limpiar" value="Reset" style="width:100px;font-size:15px;color:#ffffff;background:#999999" class="cursor" />
        </div>
</td>
<td>
<div align="center">
          <input name="entrar" type="submit" id="entrar" value="Ingresar" style="width:100px;font-size:15px;color:#ffffff;background:#999999" class="cursor" />
        </div>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
Perdona los fallos, ahora te lo pongo correctamente por ficheros ;)
funciones.php
----------------------
<?php
    function check($usuario, $clave){
        return ($usuario == "webmaster" && $clave == "123456");
    }
    function logged(){
        if(isset($_POST[user]) && isset($_POST[password])){
            $_SESSION = $_POST;
            return check($_POST[user],$_POST[password]);
        }else{
            if(check($_SESSION[user],$_SESSION[password])){
                return true;
            }else{
                return false;
            }
        }        
    }
?>
---------------
index.php
---------------------------------
<?php
    session_start();
    if(isset($_GET[logout])){
        session_unset();
    }
    require_once('./funciones.php');
    echo '
<html>
<body>
';
    if(logged()){
       echo 'logged<br><a href="index.php?logout">Cerrar sesión</a>';//codigo de la pagina a la que solo se accede logueado
    }else{
        include("form.php");
        show_form();
    }
    echo '
</body>
</html>
';
?>
-----------------------------------
form.php
-------------------------------------------
<?php
    function show_form(){
        echo '
        <form action="index.php" method="post">
<table width="366" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#787878">
<tr>
<td width="358" height="121" valign="middle" bgcolor="#FFFFFF">
<table width="358" height="126" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" bordercolor="#787878">
<tr bgcolor="#2872ae">
<td height="18" colspan="3">
<div align="center" class="Estilo4 Estilo4 Estilo10 Estilo3 Estilo1">PERSONAL DE BIBLIOTECA</div>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="25" height="36"> </td>
<td width="150" class="Estilo5 Estilo10">Usuario:</td>
<td width="183"><input name="user" type="text" id="user" size="20" maxlength="20" /></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="36"> </td>
<td class="Estilo5 Estilo10">Password:</td>
<td><input type="password" name="password" size="20" maxlength="20" /></td>
</tr>
<tr >
<td colspan="2">
<div align="center">
                                    <input name="entrar2" type="reset" id="limpiar" value="Reset" style="width:100px;font-size:15px;color:#ffffff;background:#999999" class="cursor" />
                                </div>
</td>
<td>
<div align="center">
                                    <input name="entrar" type="submit" id="entrar" value="Ingresar" style="width:100px;font-size:15px;color:#ffffff;background:#999999" class="cursor" />
                                </div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>';
    }
?>
---------------------------------------
Por cierto, te recomiendo que uses CSS... ;)
no me has entendido form no es una paguina eso esta en el index.php
<?php
session_start();
$usuario = "webmaster";
$password= "123456";
if ($_POST['user'] =="webmaster" && $_POST['password'] =="123456") {
$_SESSION['login'] = true;
$_SESSION['user'] = 'webmaster';
header ("Location: consultar.php");
}
?>
<!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">
<!-- InstanceBegin template="/Templates/index.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>BIBLIOTECA</title>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
.Estilo1 {
    color: #FFFFFF;
    font-weight: bold;
}
-->
</style>
<style type="text/css">
<!--
.Estilo3 {font-weight: bold}
-->
</style>
<!-- InstanceEndEditable -->
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div align="center">
<p><img src="img/banerbiblioteca.png" width="963" height="175" /></p>
</div>
<hr />
<div id="contenedor"><!-- InstanceBeginEditable name="region1" -->
<p> </p>
<table width="366" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#787878">
<tr>
<td width="358" height="121" valign="middle" bgcolor="#FFFFFF">
<form action="index.php" method="post">
<table width="358" height="126" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" bordercolor="#787878">
<tr bgcolor="#2872ae">
<td height="18" colspan="3">
<div align="center" class="Estilo4 Estilo4 Estilo10 Estilo3 Estilo1">PERSONAL DE BIBLIOTECA</div>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="25" height="36"> </td>
<td width="150" class="Estilo5 Estilo10">Usuario:</td>
<td width="183"><input name="user" type="text" id="user" size="20" maxlength="20" /></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="36"> </td>
<td class="Estilo5 Estilo10">Password:</td>
<td><input type="password" name="password" size="20" maxlength="20" /></td>
</tr>
<tr >
<td colspan="2">
<div align="center">
          <input name="entrar2" type="reset" id="limpiar" value="Reset" style="width:100px;font-size:15px;color:#ffffff;background:#999999" class="cursor" />
        </div>
</td>
<td>
<div align="center">
          <input name="entrar" type="submit" id="entrar" value="Ingresar" style="width:100px;font-size:15px;color:#ffffff;background:#999999" class="cursor" />
        </div>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
<p align="center"><span class="Estilo9 Estilo8 Estilo7 Estilo6"><strong>@ Universidad Tecnológica de Panamá</strong></span></p>
<!-- InstanceEndEditable --></div>
<hr />
<p> </p>
<div id="contenedor2"><!-- InstanceBeginEditable name="EditRegion2" --><!-- InstanceEndEditable --></div>
</body>
<!-- InstanceEnd -->
</html>
esta es index entera ahy esta form y el codigo para llamar a la funcion pero no te estoy entendiendo porfa y disculpa las molestias es que no se mucho de php. estoy tratando de aprender.
este es consultar.php
<?php
 session_start();
 include("conexion.php");
 $where = "";
 $valid = false;
 $contenido = '';
 $estamentos = array(
     'A' => 'Administrativo',
    'D' => 'Docente',
    'I' => 'Investigador',
 );
if($_SESSION['login'] == false) {
//----------------Buscar por nombre en la base de datos de recursos humanos---------------------
$nombre_buscar = $_POST['nombre'];
if ($nombre_buscar !=""){
    $valid = true;
    $where .= " AND nombre1+' '+apellido1 LIKE '%{$nombre_buscar}%'";
    }
//-------------------------Buscar por estamento en la base de datos de recursos humanos-------------------
$estamento_buscar = $_POST['estamento'];
if ($estamento_buscar !="") {
    $valid = true;
    $where .= " AND estamento = '{$estamento_buscar}'";
}
//---------------------------Buscar por cedula en la base de datos de recursos humanos------------------
$cedula_buscar = $_POST['ced1'].$_POST['ced2'].$_POST['ced3'];
if ($cedula_buscar!=""){
    $valid = true;
    $ced2 = sprintf("%04s", $_POST['ced2']);
    $ced3 = sprintf("%05s", $_POST['ced3']);
    $cedula = $_POST['ced1']."-".$ced2."-".$ced3;
    //$cedula_cadena = explode("-",$cedula_buscar);    
    $where .= " AND v_carnet.cedula_emp = '{$cedula}'";
}    
//------------------------Departamento---------------------------------------------------------------
$departamento_buscar = $_POST['departamento'];
    if ($departamento_buscar != "") {
        $valid = true;
        $where .= " AND nombre_depto = '{$departamento_buscar}'";
}    
//-------------------Consulta y muestra de la informacion solicitada------------------------------
     if ($valid) {
        $sql = "SELECT epersonal_foto.foto, nombre1+' '+apellido1, estamento, nombre_depto, v_carnet.cedula_emp FROM v_carnet LEFT JOIN epersonal_foto ON v_carnet.cedula_emp = epersonal_foto.cedula_emp  WHERE 1=1" . $where;
        $rs = $db->Execute($sql);
        var_dump($db->ErrorMsg());
        $resultado = $rs->GetRows();
        $contenido .= '
<table border="5" cellpadding="15" cellspacing="10" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
';
        $contenido .= '
<tr bgcolor="#2872AE" class="Estilo1 "">
';        
        $contenido .= '<th><font color="#FFFFFF">Foto</font></th><th><font color="#FFFFFF">Nombre Compleo</font></th>
        <th><font color="#FFFFFF">Estamento</font></><th><font color="#FFFFFF">Departamento</font></th>';
        foreach ($resultado as $row) {
            $est = (array_key_exists($row[2], $estamentos)) ? $estamentos[$row[2]] : '';
            $contenido .= '
<tr>
';
            if ($row[0] == '') {
                $contenido .= '
<td>No Foto<a href="informacion.php?cedula='.$row[5].'"></a></td>
';
            }else {
                //$imagen = chunk_split(base64_encode($row[0]));
                $_SESSION['imagenes'][$row[4]] = $row[0];
                $contenido .= '
<td><a href="informacion.php?cedula='.$row[4].'"><img height="100" width="100" src="resultados.php?cedula=' . $row[5] . '&listado=1" /></a></td>
';//foto
            }
            $contenido .= '
<td><a href="informacion.php?cedula='.$row[4].'">' . utf8_encode($row[1]) . '</a></td>
';//nombre
            //$contenido .= '
<td><a href="informacion.php?cedula='.$row[5].'">' . utf8_encode($row[2]) . '</a></td>
';//apellido
            $contenido .= '
<td><a href="informacion.php?cedula='.$row[4].'">' . $est . '</a></td>
';//estamento
            $contenido .= '
<td><a href="informacion.php?cedula='.$row[4].'">' . utf8_encode($row[3]) . '</a></td>
';//departamento
            $contenido .= '
</tr>
';
        }
        $contenido .= '
</tr>
';
        $contenido .= '
</table>
';
     }else {
        $contenido = "Debe colocar un criterio de búsqueda";
     }    
 }else{
 session_unset();
 session_destroy();
 header("Location: index.php");
 }
?>
 <!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">
<!-- InstanceBegin template="/Templates/index.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>BIBLIOTECA</title>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
.Estilo3 {
    color: #FFFFFF;
    font-family:Verdana, Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-size:18px;
}
-->
</style>
<style type="text/css">
<!--
a:link {
    text-decoration: none;
    color: #000000;
}
a:visited {
    text-decoration: none;
    color: #000000;
}
a:hover {
    text-decoration: none;
    color: #000000;
}
a:active {
    text-decoration: none;
    color: #000000;
}
-->
</style>
<style type="text/css">
<!--
.Estilo4 {
    color: #FFFFFF
}
-->
</style>
<!-- InstanceEndEditable -->
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div align="center">
<p><img src="img/banerbiblioteca.png" width="963" height="175" /></p>
</div>
<hr />
<div id="contenedor"><!-- InstanceBeginEditable name="region1" -->
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100%" height="62" align="center">
<tr bgcolor="#2872ae">
<td colspan="2">
<div align="center" class=" Estilo3 Estilo4">Centro de Busqueda</div>
</td>
</tr>
<tr>
<td width="111"><strong>Nombre</strong></td>
<td width="274">
          <input name="nombre" type="text" id="usuariob" />        </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Estamento</strong></td>
<td><label>
            <select name="estamento" id="estamento">
        <option value=""></option>
        <option value="A">ADMINISTRATIVO</option>
        <option value="D">DOCENTE</option>
        <option value="I">INVESTIGADOR</option>
            </select>
          </label>       
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Cedula</strong></td>
<!-- <input name="cedula" type="text" id="cedula" maxlength="15" />-->
<td><select name="ced1" size="1" id="ced1">
          <option value=""></option>
          <option value="   E">E</option>
          <option value="   N">N</option>
          <option value="  PE">PE</option>
          <option value="1   ">1</option>
          <option value="2   ">2</option>
          <option value="3   ">3</option>
          <option value="4   ">4</option>
          <option value="5   ">5</option>
          <option value="6   ">6</option>
          <option value="7   ">7</option>
          <option value="8   ">8</option>
          <option value="9   ">9</option>
          <option value="10  ">10</option>
          </select>- <input type="text" size="4" maxlength="4" name="ced2"/>
          -<input type="text" size="5" maxlength="5" name="ced3" /></td>
</tr>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><strong>Departamento</strong></td>
<td><label>
            <select name="departamento" id="departamento">
              <?php
              print"<option value=''></option>";
            $sql = "Select nombre_depto From v_carnet group by nombre_depto order by nombre_depto";
            $rs = $db->Execute($sql);
            $resultado = $rs->GetRows();
            foreach ($resultado as $row){
                echo '<option value="' . $row[0] . '">' . $row[0] . '</option>';
            }
            ?>
            </select>
          </label></td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<p>
              <input type="submit" name="Buscar" id="Buscar" value="Buscar" />
              <input type="reset" name="limpiar" id="limpiar" value="Reset" />
            </p>
<p align="right"><a href="index.php">Regresar</a></p>
</div>
</td>
</tr>
</table>
</form>
<p>
    <input type="hidden" name="cedula" />
  </p>
<p>   </p>
<!-- InstanceEndEditable --></div>
<hr />
<p> </p>
<div id="contenedor2"><!-- InstanceBeginEditable name="EditRegion2" -->
<p> <?php echo $contenido; ?>
   </p>
<!-- InstanceEndEditable --></div>
</body>
<!-- InstanceEnd -->
</html>
las consultas estan bien solo es lo del login que no he podido hacer.
no será en consultar.php 
if($_SESSION['login'] == TRUE) { // ????????????????
y por cierto, para destruir la sesión es tan facil como session_unset();
Saludos. (Espero que sea lo qeu buscas. XDD)
Por cierto, no se si es tu codigo o la forma que tabula esto, pero hay cosas que noe stán comentadas y deberían estarlo
Estilo...
 // $variable = '
codigo html ';
(Deberías comentarla entera, creo) o ponerla entre /* y */

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas