Código:
<?php //simple PHP login script using Session //start the session * this is important session_start(); //login script if(isset($_REQUEST['ch']) && $_REQUEST['ch'] == 'login'){ //give your login credentials here if($_REQUEST['uname'] == 'usuario' && $_REQUEST['pass'] == 'password') $_SESSION['login_user'] = 1; else $_SESSION['login_msg'] = 1; } //get the page name where to redirect if(isset($_REQUEST['pagename'])) $pagename = $_REQUEST['pagename']; //logout script if(isset($_REQUEST['ch']) && $_REQUEST['ch'] == 'logout'){ unset($_SESSION['login_user']); header('Location:login.php'); } if(isset($_SESSION['login_user'])){ if(isset($_REQUEST['pagename'])) header('Location:'.$pagename.'.php'); else header('Location:recursos.php'); }else{ ?> <!DOCTYPE> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>FPG</title> <link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="css/960.css"> <link rel="stylesheet" href="css/bootstrap.min.css"> <script src="js/bootstrap.min.js"></script> </head> <body> <div class="wrapper" style="background:#FFF;"> <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr><td> </td></tr> <tr><td> <form name="login_form" method="post" action=""> <table align="center" style="background-color:#fff;"> <tr><td align="center"></td></tr> <tr> <td align="center"><h3>Iniciar Sesion</h3></td> </tr> <tr><td style="text-align:center;"><input type="text" name="uname" id="uname" placeholder="Usuario"></td></tr> <tr><td style="text-align:center;"><input type="password" name="pass" id="pass" placeholder="Contraseña"></td></tr> <tr> <td align="center"> <p style="color:red;"> <?php //display the error msg if the login credentials are wrong! if(isset($_SESSION['login_msg'])){ echo '<div class="alert alert-error">'; echo '<span class="label label-important">Atención!</span>'; echo ' El usuario o la contraseña no son válidos'; echo '</div>'; unset($_SESSION['login_msg']); } ?> </p> </td></tr> <tr><td align="center"><input type="submit" value="Ingresar" class="btn"></td></tr> </table> <input type="hidden" name="ch" value="login"> </form> </td></tr> </table> </div> <div class="clear"></div> <?php } ?> </body> </html>