Hello PHPBuilder, I am having a little problem. I seem to get a unexpected colon error, but when I remove it, I get an T_STRING error caused by the missing colon. Here is my code.

<?php
if (isset($_POST['user'])) {
     if (isset($_POST['pass'])) {
           $file = fopen("/.htpasswds/public_html/view/passwd", 'a') or die("can't open file");
           fwrite($file, "\n" . $_POST['user'] . ":" . crypt($_POST['pass'], base64_encode($_POST['pass']));
           fclose($file);
           echo "The deed has been done.<br />";
     }
}
?>

<form name="input" action="add.php" method="post">
Username: <input type="text" name="user" />
Password: <input type="text" name="pass" />
<input type="submit" value="Submit" />
</form>

Can anyone help?

    When posting PHP code, please use the board's [noparse]

    ..

    [/noparse] bbcode tags (not the generic CODE tags) as they make your code much easier to read and analyze.

    As for your problem, the parse error I got was in regards to an unexpected semicolon, not a colon. The cause of this error is a missing ')' on that line (e.g. to close the '(' for fwrite()).

      Thank you very much, that fixed the problem, and I finished the code.

      <?php 
      function crypt_apr1_md5($plainpasswd) {
          $salt = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
          $len = strlen($plainpasswd);
          $text = $plainpasswd.'$apr1$'.$salt;
          $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd));
          for($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); }
          for($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $plainpasswd{0}; }
          $bin = pack("H32", md5($text));
          for($i = 0; $i < 1000; $i++) {
              $new = ($i & 1) ? $plainpasswd : $bin;
              if ($i &#37; 3) $new .= $salt;
              if ($i % 7) $new .= $plainpasswd;
              $new .= ($i & 1) ? $bin : $plainpasswd;
              $bin = pack("H32", md5($new));
          }
          for ($i = 0; $i < 5; $i++) {
              $k = $i + 6;
              $j = $i + 12;
              if ($j == 16) $j = 5;
              $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp;
          }
          $tmp = chr(0).chr(0).$bin[11].$tmp;
          $tmp = strtr(strrev(substr(base64_encode($tmp), 2)),
          "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
          "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
          return "$"."apr1"."$".$salt."$".$tmp;
      }
      
      if (isset($_POST['user'])) { 
           if (isset($_POST['pass'])) { 
                 $file = fopen("/home/myname/.htpasswds/public_html/view/passwd", 'a') or die("can't open file"); 
                 fwrite($file, "\n" . $_POST['user'] . ":" . crypt_apr1_md5($_POST['pass'])); 
                 fclose($file); 
                 echo "The deed has been done.<br />"; 
           } 
      } 
      ?> 
      
      <form name="input" action="add.php" method="post"> 
      Username: <input type="text" name="user" /> 
      Password: <input type="text" name="pass" /> 
      <input type="submit" value="Submit" /> 
      </form>

      Problem resolved.

        Write a Reply...