Hola, he probado dos sistemas de acceso restringido a una página, pero ninguno de los dos me ha funcionado correctamente, son éstos:
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
<html xmlns="http://wwww.w3.org/1999/xhtml">
<head>
<title>ensayo1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="noindex, nofollow" />
<html>
<head>
<body>
<form method="POST" action="ensayo2.php">
<p>Usuario: <input type="text" name="usuario" size="10"><br>
Password: <input type="password" name="password" size="10"><br>
<input type="submit" value="Enviar" name="privado"></p>
</form>
</body>
</html>
<?
// Comparamos a ver si son correctos
if ($usuario=="alguien" && $password=="almendra57")
{
$valido="si";
}
else
{
$valido="no";
}
?>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
<html xmlns="http://wwww.w3.org/1999/xhtml">
<head>
<title>ensayo2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="noindex, nofollow" />
<style type="text/css">
* {
margin:0;
padding:0;
border: 0;
position: relative;
}
body {
background: black;
margin: 0 auto;
text-align: center;
}
#contenido {
width: 650px;
position: relative;
background: white;
padding-top: 40px;
}
h2 {
font: normal, 14px Arial, sans-serif;
text-align: center;
color: green;
}
</style>
</head>
<body>
<? if ($valido=="si")
{
?>
'
<center>
<div id="contenido">
<br /><br />
<p><img src="atardecer.jpg" title="atardecer sobre el mar></img></p>
<br /><br /><br />
<h2>El ocaso marino es muy especial</h2>
</div>
<br /><br />
<? }
else
{
?>
<p>USUARIO O CONTRASEÑA INCORRECTA</p>
</center>
<? } ?>
</body>
</html>
En este primer ensayo, tras introducir el usuario se visualiza este aviso de error:
Parse error: syntax error unexpected T_STRING, expecting ',' or 'i' in var/www/host/misitio.com/home/html/ensayos/ensayo1.php on line 9
El segundo código es el siguiente:
<html>
<head>
<title>esto</title>
</head>
<body>
<form action="parte1.php" method="post">
Clave de acceso:<input type="password" name="acceso" size="12">
<input type="submit" value="Entrar">
</form>
</body>
</html>
<?php
$acceso = $_POST["acceso"];
if ($acceso <> almendra57) {
echo " <html>
<head>
<title>Aviso</title>
</head>
<body>
<a href="parte1.php">Acceso denegado, vuelve a intentarlo</a>
</body>
</html>";
}else{
echo "<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">
<html xmlns="http://wwww.w3.org/1999/xhtml">
<head>
<title>parte2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Robots" content="noindex, nofollow" />
<style type="text/css">
* {
margin:0;
padding:0;
border: 0;
position: relative;
}
body {
background: black;
margin: 0 auto;
text-align: center;
}
#contenido {
width: 650px;
position: relative;
background: white;
padding-top: 40px;
}
h2 {
font: normal, 14px Arial, sans-serif;
text-align: center;
color: green;
}
</style>
</head>
<body>
<center>
<div id="contenido">
<br /><br />
<p><img src="atardecer.jpg" title="atardecer sobre el mar></img></p>
<br /><br /><br />
<h2>El ocaso marino es muy especial</h2>
</div>
<br /><br />
</body>
</html>
}
?>
En este caso la inserción del usuario y la contraseña sí aparece la página siguiente, pero completamente vacía de contenido.
¿Alguien puede indicarme si hay algún fallo visible en los códigos?