If you have access to the .htaccess file, then you can change where it looks for the .htpasswd file... so essentially, you do have access to the .htpasswd file. Although, in the example you gave, it seems to use a file called passwd, not .htpasswd. (You can name the file anything you like).
http authentication is typically more secure because the professionals have already addressed many of the common mistakes that people make when they roll their own php/mysql login.
http authentication is typically faster to implement too because it usually doesn't require any coding on your part.
Both methods have their advantages. Either one can be implemented badly so you can't say that http authentication is always more secure.
By the way, you can't put quotes inside of quotes so this line won't work:
header("WWW-Authenticate: Basic realm="Authorization Required!"");
Try this instead:
$string = "WWW-Authenticate: Basic realm=\"Authorization Required!\"";
header($string);
Or maybe this:
header("WWW-Authenticate: Basic realm='Authorization Required!'");
Google for htaccess for windows to find the syntax to create an .htpasswd file for Windows. I found a number of examples.