制作目录时出错

I'm new to PHP and I'm trying to create a directory (for a user) and I get a 500 Error when the script is launched.

<html>
<head>
    <title>Login</title>
</head>
<body>
    <?php 
        chdir("users");
        mkdir($_POST["username"]);
    ?>
</body>

Your error log will usually have a more detailed error message. I'd guess it's permissions though.

Make sure your web service is allowed to create directories in the "user" dir.

The most likely problem here is that th3 user folder doesn't have www-data as user or group, and then write permissions. You should lookup these things and set them if they aren't correct.

This is pretty bad practice to make a directory like that, but to answer your question you probably need to check and make sure you have that variable first, before you try to work with it. Like this.

if(isset($_POST["username"])){
        mkdir($_POST["username"]);
}

The reason being that variable in the post isn't always there, its only there when you populate it, typically by submitting a form

first of all your problem can be caused by a huge amount of reasons so you need to narrow those down: turn error reporting ON.

Seccond, use the full, absolute path to create a directory so you don't get lost in your OS.

This way you can find out what the problem is, try this:

<html>
 <head>
  <title>Login</title>
 </head>
 <body>
  <?php 
    error_reporting(E_ALL);
    mkdir(/home/$_POST["username"]);
  ?>
 </body>