DUDA LOGIN (sin MySQL)

Battosai

Wenas!!! estoy haciendo un foro php sin mysql, usando en vez de tablas, archivos .txt . Estoy haciendo el formulario del login pero no me funciona, aver si me podeis ayudar. Aki os dejo el codigo i la duda :

$reg="registros.txt";
$gestor=fopen($reg, "r");
$contenido=fread($gestor, filesize($reg));
fclose($gestor);

$registros = explode("<registro>", $gestor);
$i = 0;
while(isset($registros[$i])){

$camp = explode("<camps>", $registros[$i]);

$i=($i+1);

if("$camp[0] && $camp[1]" == //EL CAMPO [0] i el CAMPO [1] DEBERIAN ESTAR LOCALIZADOS EN EL REGISTRO[x] esto es lo k no se hacer :S:S ){
echo "OK!";

}

else{
echo "PW or User are incorrect";
}
}
?>

PD : lo hariais asi vosotros? o hay alguna manera mas sencilla de relacionar usuario i password? thx

Gracias de antemano;)

guner

Yo en estos casos sulo tirar de expresiones regulares.

<?php

$str = @fread($fp = fopen('us.txt', 'r'), filesize('us.txt')); //@ 0 length warning
fclose($fp);

$POST['u'] = 'Juan_Palomo';
$
POST['p'] = 'yomeloguisoyomelocomo';

$POST['u'] = 'María Isabel';
$
POST['p'] = 'antesmuertaquesinsilla';

$regexp =
&nbsp; &nbsp; &nbsp; &nbsp; '#!NU{'&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; .'(' . preg_quote((bool) get_magic_quotes_gpc() ? $POST['u'] : addslashes($POST['u'])) . ')'
&nbsp; &nbsp; &nbsp; &nbsp; . '::'
&nbsp; &nbsp; &nbsp; &nbsp; . '(' . md5((bool) get_magic_quotes_gpc() ? $POST['p'] : addslashes($POST['p'])) . ')'
&nbsp; &nbsp; &nbsp; &nbsp; . '}#';

#echo $str; #dbg
#echo get_magic_quotes_gpc(); #dbg
#echo $regexp; #dbg

$arr = array();
if (preg_match($regexp, $str, $arr)) echo "EXISTE";
#var_dump($arr); #dbg

?>

us.txt:

!NU{Juan_Palomo::da282a87f87a95c1096612365c82184c}
!NU{María Isabel::15dca33496460e04e90a015a4e1f10e0}

Usuarios habituales

  • guner
  • Battosai