In short, I did one thing and decided that I did not want to use the database, but try to do everything through files. So here. I did the registration to the file, checking everything that is necessary, everything is as it should be. But the problem with the entrance. The structure of the file with user data is as follows:

|-ник-пароль 

So here. Trying to parse through a bunch of explod and foreach, here’s what comes out:

  <?php session_start(); $_SESSION['lcnick']=stripslashes($_POST['nick']); $r=file_get_contents('users.dat'); $rr=explode('|',$r); foreach ($rr as $v1) { $rrr=explode('-',$v1); if ($rrr['0']==$_SESSION['lcnick'] && $rrr['1']==$_POST['pass']) { $_SESSION['cnick']=$_SESSION['lcnick']; header('index.php'); } } ?> 

cnick is the user's primary nickname, lcnick is a temporary nickname variable. In short, after a painful debug, I found out that password parsing from a file by the second attribute does not work ("|" is the first sign - this is how the account itself (-nik-password) is parsed, then the second sign goes - "-", this is the zero index ( Nick) and the first (Password). So the password does not want to fall into the array. If someone understands, can you help?

  • The tag is correct. And what's not wanting to use the database? - --A
  • I just don't want to. I wanted to make friends with files. - gorguelike
  • Show the contents of users.dat, for example. - --A
  • There is only one entry: | -gorgilike-123 - gorguelike
  • one
    @gorguelike, you are now faced with a very important thing. The functionality of reading from files - like the database - should lie and work separately from everything else. Then you can test it normally and make sure that everything works correctly, and only then pick up external handlers. In other words, you need a set of functions / methods that will rip out the data from the file (for a start, it’s enough to "select all" and "select with such values ​​of such columns"). As for the format - I would use csv, everything is easier with it, it’s easier to see the work of the neighboring library and compare rt - etki

1 answer 1

If it is your code to pick, then something like this (replace back variables and use). In general, Etki wrote everything correctly in the comments.