Denegar acceso por ip

Iniciado por teudiss, 13 Abril 2010, 09:49 AM

0 Miembros y 1 Visitante están viendo este tema.

teudiss

Hola, quiero que a mi web solo tengan acceso 2 ip´s de mi intranet tengo el siguiente script pero no me funciona como quiero. Las ip´s que quiero que accedan estan en una tabla de mi base de datos.


Citar<?php
include("Connections/ip.php");

$ip_adress=$_SERVER['REMOTE_ADDR'];
$busqueda= mysql_query("SELECT ip FROM maquina WHERE ip='".$_SERVER['REMOTE_ADDR']."'",$ip) or die(mysql_error());

         
if(mysql_num_rows($busqueda)>0) {  
  echo "aqui quiero que me lea el codigo html";
   
} else
{
echo "acceso denegado";
}

?>

<!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">
<head>
<body>
<style type="text/css">
<!--
body {
   background-color: #0066FF;
}
.Estilo1 {font-size: 24px}
-->
</style><form action="validar_usuario.php" method="post">
 <div align="center">
   <p>&nbsp;</p>
   <p class="Estilo1"></p>
   <p>&nbsp;</p>
   <table width="200" border="2">
     <tr>
       <th scope="row">Contrase&ntilde;a</th>
       <td><input name="password" type="password" id="password" size="10" maxlength="10" /></td>
     </tr>
   </table>
   <p>
     <input type="submit" value="Aceptar" />
   </p>
   <br />
 </div>
</form>
</head>
</body>
</html>


WHK

asi?

Código (php) [Seleccionar]
<!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">
<head>
<body>
 <style type="text/css">
  <!--
  body {
   background-color: #0066FF;
  }
  .Estilo1 {font-size: 24px}
  -->
 </style>
</head>
<body>
<?php
include("Connections/ip.php");
if(
mysql_query("
 select ip from maquina
 where ip='"
.mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."'
 limit 1
"
$ip)){
?>


<form action="validar_usuario.php" method="post">
 <div align="center">
   <p>&nbsp;</p>
   <p class="Estilo1"></p>
   <p>&nbsp;</p>
   <table width="200" border="2">
     <tr>
       <th scope="row">Contrase&ntilde;a</th>
       <td><input name="password" type="password" id="password" size="10" maxlength="10" /></td>
     </tr>
   </table>
   <p>
     <input type="submit" value="Aceptar" />
   </p>
   <br />
 </div>
</form>

<?php }else{ ?>
acceso denegado
<?php ?>

</body>
</html>


teudiss

No me funciona, (no da ningun error) puede acceder cualquier equipo.

En mi tabla solo tengo mi ip (127.0.0.1).....:(

Castg!

pero que error te da?

porq no imprimis tu ip para asegurarnos cual es!? tenes dominio no-ip y estas entrando por ahi?

cambia el acceso denegado por esto:

Código (php) [Seleccionar]

{
die("Acceso denegado");
}

winroot

hola,

y si usas archivos .httaccess?

creo que es lo mejor
saludos
Mi blog sobre programación y seguridad informática:
http://win-root.blogspot.com

Castg!

Código (apache) [Seleccionar]
<Limit GET POST>
order deny,allow
allow from 127.0.0.1
deny from all
</Limit>


creo que ahi iria.

teudiss

Cita de: Castg! en 13 Abril 2010, 16:07 PM
Código (apache) [Seleccionar]
<Limit GET POST>
order deny,allow
allow from 127.0.0.1
deny from all
</Limit>


creo que ahi iria.

Ya me funciona con este codigo.


Citar
   
<?php
include("Connections/ip.php");


$busqueda= mysql_query("SELECT ip FROM maquina WHERE ip='".$_SERVER['REMOTE_ADDR']."'",$ip) or die(mysql_error());

         
if(mysql_num_rows($busqueda)!=0){   
   
<!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">
<head>
<body>
<style type="text/css">
<!--
body {
   background-color: #0066FF;
}
.Estilo1 {font-size: 24px}
-->
</style><form action="validar_usuario.php" method="post">
</head>
  <div align="center">
    <p>&nbsp;</p>
    <p class="Estilo1"></p>
    <p>&nbsp;</p>
    <table width="200" border="2">
      <tr>
        <th scope="row">Contrase&ntilde;a</th>
        <td><input name="password" type="password" id="password" size="10" maxlength="10" /></td>
      </tr>
    </table>
    <p>
      <input type="submit" value="Aceptar" />
    </p>
    <br />
  </div>
</form>
<?php }else{ ?>acceso denegado<?php } ?>

</body>
</html>



Muchas Gracias por la ayuda

Castg!

denada, ahora, si queres, podes personalizar el error 403 Forbbiden Page, asi no siempre te dice el mensaje de apacha, podes hacer una pagina vos y desapues indicarle a apache que esa pagina habra cuando da este error, 403.

Código (apache) [Seleccionar]
ErrorDocument 403 pagina403.html

WHK

no necesitas el mysql_num_rows() pero bueno, ahi ves.

-explicito-

apf -d IP
jkajaja... eso es a nivel server sorry.

<Limit GET POST>
order deny,allow
allow from 127.0.0.1
deny from all
</Limit>

Esa es la mejor manera.
Ahora si quieres un banneador automatico hay que tocar mas cosas