Well, I have no idea whats going on... But here is the problem:

I have these files:

$file2 = "password_protect.php";
$newfile = $newDir . "/password_protect.php";
if (!copy($file2, $newfile)) {
    echo "Creation failed.";
}
else{
chmod($newfile, 0777);
chmod("passProcess.php", 0777);
echo "Step 1/2 completed.<br />"
?>
<form action="passProcess.php?var=Users/<?PHP echo $projectname  ?>/" method="post">
New password: <input type="text" name="addition"/><br/>
<input type="submit"/>
</form>
<?php
}
<?php 
 echo $_GET['var'] . "<br />"; 
 echo $_POST['addition']; 
 $File = "creativecodingstudios.com/connect/" . $_GET['var'];
 $Handle = fopen($File, 'a'); 
 $Data = "$password = " . $_POST['addition']; 
 fwrite($Handle, $Data); 
 print "Data Added"; 
 fclose($Handle); 
 ?>

But on the second code, I get a 500 error. Why?

Dani AI

Generated

Two quick red flags from the snippets: a PHP syntax error in the first script (missing semicolon before the PHP close tag) and a wrong target for fwrite/fopen in the second script — the code builds a domain-like string (creativecodingstudios.com/connect/...) instead of a local filesystem path, and it looks like a directory is being opened rather than a filename. Both will commonly produce an HTTP 500 when errors are fatal or error reporting is hidden.

Enable full error output temporarily to get the exact cause (parse error, permission denied, etc.):

ini_set('display_errors', 1);
error_reporting(E_ALL);

Confirm the exact error and line number in the PHP/Apache error log if display is disabled (server logs or hosting control panel).

Save and write using a real filesystem path and check everything before calling fopen. Example pattern:

$dir  = $_SERVER['DOCUMENT_ROOT'] . '/connect/' . trim($_GET['var'], '/');
$file = $dir . '/password_protect.php';

if (!is_dir($dir)) mkdir($dir, 0755, true);
if (!is_writable($dir)) error_log("Permissions problem: $dir");

$h = @fopen($file, 'a');
if ($h === false) {
    error_log("fopen failed for $file");
    exit;
}
fwrite($h, "<?php \$password = " . var_export($_POST['addition'], true) . ";\n");
fclose($h);

Additional notes and cautions: avoid leaving display_errors on in production; prefer controlled error checks instead of assuming success; 0777 is rarely necessary — fix ownership (chown) if possible; check for open_basedir/safe_mode or disabled functions on shared hosts; always sanitize and quote values when writing PHP code to avoid creating parse errors in the written file. This addresses ’s symptoms and echoes ’s correct suspicion about the path: verify $newDir and build a proper filename (not just a directory) before fopen.

Hello CreativeCoding

I have read your post but i can not understand what are you truing to do?
Do you want to write password in file ($File)?

Is the $newDir path is correct?
Have you specify what $newDir contain?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.