Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - 0x0309

#11
PHP / Filtro SQL Injection y Filtro XSS
13 Octubre 2009, 06:20 AM
Aquí comparto dos funciones que hice para prevenir sql injection y xss.

El código está en base64, una vez que lo decodifican, pueden guardarlo como Filtros.php y requerirlo en su script.



PD9waHANCg0KIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjDQojIEZpbHRybyBw
YXJhIGV2aXRhciBTUUwgSW5qZWN0aW9uICMNCiMgdmVyc2lvbjogMC4xICAgICAgICAgICAgICAg
ICAgICAgIw0KIyBBdXRvcjogMHgwMzA5ICAgICAgICAgICAgICAgICAgICAjDQojIyMjIyMjIyMj
IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMNCmZ1bmN0aW9uIGFudGlTUUxJbmplY3Rpb24oJHN0
cikNCnsNCiAgICBpZiAoaXNfc3RyaW5nKCRzdHIpKSB7DQogICAgICAgICAvL2VuIHBocCA2IG1h
Z2ljIHF1b3RlcyB5YSBubyB2YW4NCiAgICAgICAgaWYgKGdldF9tYWdpY19xdW90ZXNfZ3BjKCkp
IHsNCiAgICAgICAgICAgICRzdHIgPSBzdHJpcHNsYXNoZXMoJHN0cik7DQogICAgICAgIH0NCiAg
ICAgICAgJHN0ciA9IG15c3FsX3JlYWxfZXNjYXBlX3N0cmluZygkc3RyKTsNCiAgICAgICAgJHN0
ciA9IGFkZGNzbGFzaGVzKCRzdHIsICclXycpOw0KICAgIH0NCiAgICByZXR1cm4gJHN0cjsNCn0N
Cg0KIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw0KIyBGaWx0cm8g
cGFyYSBldml0YXIgQ3Jvc3MtU2l0ZSBTY3JpcHRpbmcgIw0KIyB2ZXJzaW9uOiAwLjEgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgIw0KIyBBdXRvcjogMHgwMzA5ICAgICAgICAgICAgICAgICAg
ICAgICAgICAgIw0KIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw0K
ZnVuY3Rpb24gYW50aUNyb3NzU2l0ZVNjcmlwdGluZygkc3RyKQ0Kew0KICAgIGlmIChpc19zdHJp
bmcoJHN0cikpIHsNCiAgICAgICAkc3RyID0gaHRtbGVudGl0aWVzKCRzdHIsIEVOVF9RVU9URVMs
ICdVVEYtOCcpOw0KICAgIH0NCiAgICByZXR1cm4gJHN0cjsNCn0NCg0KPz4=


y pueden usarlo así:


//Para consultas a base de datos:
//Si el campo id de la base de datos es string :
$id = antiSQLInjection( $_POST['id'] );
//Sino si el campo id de la base de datos es entero:
$id = (int) $_POST['id'];

$query = "select nombre from usuario where id='{$id}'";
mysql_query($query);


//Para imprimir:
echo antiCrossSiteScripting($_POST['texto']);



#12
PHP / Re: Pegar imagenes en php
13 Octubre 2009, 02:17 AM
Ok, gracias.
#13
PHP / Pegar imagenes en php
12 Octubre 2009, 22:04 PM
Hola, tengo un pequeño problema, estoy generando imagenes de niveles de sokoban dinámicamente.

El problema es que para que en pantalla se muestre algo así:



Este es el código que genero con php:

Código (html) [Seleccionar]

<img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/box.gif" width="16" height="16"  /><img src="http://midominio/images/player.gif" width="16" height="16"  /><img src="http://midominio/images/box.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/box.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/box.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/goal.gif" width="16" height="16"  /><img src="http://midominio/images/goal.gif" width="16" height="16"  /><img src="http://midominio/images/goal.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/box.gif" width="16" height="16"  /><img src="http://midominio/images/goal.gif" width="16" height="16"  /><img src="http://midominio/images/goal_box.gif" width="16" height="16"  /><img src="http://midominio/images/goal.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/goal.gif" width="16" height="16"  /><img src="http://midominio/images/goal_box.gif" width="16" height="16"  /><img src="http://midominio/images/goal.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/box.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/box.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><br/>
<img src="http://midominio/images/floor.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/wall.gif" width="16" height="16"  /><img src="http://midominio/images/floor.gif" width="16" height="16"  /><br/>
<br/>


Y obviamente, el htm generado pesa mucho, por lo que tendré problemas de ancho de banda, por ejemplo, para unos 100 niveles, el htm pesa más de un mega.

Tengo pensado evitar:

width="16" height="16

y poner class="algo" y especificar el tamaño con css.

Sin embargo de todas formas, es mucho código, así es que me gustaría poder pegar todas las imagenes, ¿se puede hacer con php dinámicamente? y así generar una sola imagen para que el htm quede:

<img src="http://midominio/images/imagenGenerada.gif"  />

Si se puede, podría generar todas las imágenes, y subirlas a otro hosting, por ejemplo imageshack, así me ahorro un montón de ancho de banda.


Nota: cada cuadro de 16*16 de la imagen que muestro es una imagen, por ejemplo: wall.gif es el bloque de muralla, floor.gif es el bloque negro, etc.
#14
genial información, me ha gustado de verdad, yo miraba smf como algo bien seguro, pero por lo que dices, hay que revisarlo.

Voy a guardar este post.
#15
PHP / Re: consulta me inserta 2 veces
8 Octubre 2009, 09:00 AM
a lo mejor no definiste clave primaria.
#16
PHP / Sugerencia login
7 Octubre 2009, 07:44 AM
Hola, estoy recién comenzando a jugar con las sesiones, quisiera recibir por favor sugerencias sobre este script para comprender bien la lógica.
Edito: tenía un problema, pero edito, ahora me gustaría recibir sugerencias sobre cómo mejorar el script.


Le he añadido protección básica contra fijación de sesiones y cross site request forgeries.

Código (php) [Seleccionar]

<?php

session_start
();


if (!isset(
$_SESSION['logeado']))
{
if ($_POST['user'] == 'carlos' && $_POST['password'] == 'entrar')
{
session_regenerate_id();
$_SESSION['logeado'] = true;
$_SESSION['token'] = md5(uniqid(rand(), TRUE));
}
} else if (
$_POST['logout'])
{
if (isset($_SESSION['token']) &&
        
$_POST['token'] == $_SESSION['token'])
    
{
      
$_SESSION = array();
   
session_destroy();
    
}

}

if (
$_SESSION['logeado'] == true)
{
   
echo 'Contenido exlusivo' '<br />';
}


?>



<html>

<body>

<?php

if ($_SESSION['logeado'] == false)
{
?>

   <form method='POST' action='login.php'>
   User:
    <input name="user" type="text" maxlength="50" size="20" />
   Password:
    <input name="password" type="text" maxlength="50" size="20" />
    <input name="login" type="submit" value="Login" />
   </form>
   
<?php 
} else
{
?>

   
   <form method='POST' action='login.php'>
    <input name="token" type="hidden" value="<?php echo $_SESSION['token']; ?>" />
    <input name="logout" type="submit" value="Logout" />
   </form>

<?php
}
?>

   
</body>
   
</html>

#17
gracias, buscaré un hosting que me de mi php.ini
#18
Tengo esa duda:
¿Se puede tener una configuración personalizada de php en un servidor compartido?

Me gustaría contratar un hosting barato (compartido), pero me gustaría tener mi configuración personal de php, por ejemplo, deshabilitar las magic quotes, y establecer la conexión por defecto a la bd dentro de la configuración de php, así me evito exponer los datos de la bd innecesariamente.

Mi pregunta es si se puede.
#19
Claro, reemplaza por esto:


for %%f in ("%rutaArchivo%") do for %%e in (.txt .src .log "") do if "%%~xf"=="%%~e" goto :Valido

#20
Podrías hacer:


set rutaArchivo=C:\archivo.txt

for %%f in ("%rutaArchivo%") do for %%e in (.txt .src .log) do if "%%~xf"=="%%e" goto :Valido


:noValido
echo.Extension no valida.
goto :eof

:Valido
echo.Valido
pause