Page 1 of 1
Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 2:21 am
by mtb211
Code: Select all
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$dir = $uname;
$user = $_POST['user'];
$pass = $_POST['pass'];
// current list
$thisdir = str_replace(strrchr($_SERVER['SCRIPT_FILENAME'],'/'), '', $_SERVER['SCRIPT_FILENAME']);
// What the list should provide
$oldumask = umask(0);
mkdir($dir,0777);
umask($oldumask);
// Daten für .htaccess erstellen
$htaccess = 'AuthType Basic
AuthUserFile '.$thisdir.'/'.$dir.'/.htpasswd
AuthName "Geschuetzer Bereich"
order deny,allow
allow from all
require valid-user';
// data for htpassword
$htpasswd = $uname.':'.crypt($pw, substr(md5(uniqid(rand())), 0, 2));
// Testdatei erstellen (wird angezeigt beim erfolgreichen Login)
$handle = fopen($dir.'/index.php', 'w');
fwrite($handle, '
<?
echo "Hier sind die Bereitgestellten Dateien<br><br>";
$action=opendir("./");
while($datei=readdir($action)){
if(!preg_match("!(\.|\..)$!", $datei)){
if ($datei!="index.php" && $datei!=".htaccess" && $datei!=".htpasswd" ) {
echo "
<a href=\"$datei\">
$datei</a><br>"; } } } ?>');
fclose($handle);
// .htaccess data
$handle = fopen($dir.'/.htaccess', 'w');
fwrite($handle, $htaccess);
fclose($handle);
// .htpasswd data
$handle = fopen($dir.'/.htpasswd', 'w');
fwrite($handle, $htpasswd);
fclose($handle);
?>
</body>
</html>
Thanks in advance!
ps. I didnt write this code... a contractor before I arrived did
Re: Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 2:30 am
by jaoudestudios
Some code is missing!
PHP tags are open then they are opened again.
Re: Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 2:32 am
by mtb211
Im a bit new to this.. any idea what exactly missing? If I can not contact the devolper is it possible for me to figure this out?
Thanks for the quick response
Re: Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 2:34 am
by jaoudestudios
Are you able to translate the comments into English? This might help.
Re: Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 2:41 am
by mtb211
lol hey, my germany isnt great... erstellen means like to provide...
I edited the top file
probally not much help
Re: Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 3:20 am
by requinix
Actually guys, if you looked a little harder you'd realize that there's nothing missing.
That's right. The code is valid. Watch:
Code: Select all
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$dir = $uname;
$user = $_POST['user'];
$pass = $_POST['pass'];
// current list
$thisdir = str_replace(strrchr($_SERVER['SCRIPT_FILENAME'],'/'), '', $_SERVER['SCRIPT_FILENAME']);
// What the list should provide
$oldumask = umask(0);
mkdir($dir,0777);
umask($oldumask);
// Daten für .htaccess erstellen
$htaccess = 'AuthType Basic
AuthUserFile '.$thisdir.'/'.$dir.'/.htpasswd
AuthName "Geschuetzer Bereich"
order deny,allow
allow from all
require valid-user';
// data for htpassword
$htpasswd = $uname.':'.crypt($pw, substr(md5(uniqid(rand())), 0, 2));
// Testdatei erstellen (wird angezeigt beim erfolgreichen Login)
$handle = fopen($dir.'/index.php', 'w');
fwrite($handle, '
<?
echo "Hier sind die Bereitgestellten Dateien<br><br>";
$action=opendir("./");
while($datei=readdir($action)){
if(!preg_match("!(\.|\..)$!", $datei)){
if ($datei!="index.php" && $datei!=".htaccess" && $datei!=".htpasswd" ) {
echo "
<a href=\"$datei\">
$datei</a><br>"; } } } ?>');
fclose($handle);
// .htaccess data
$handle = fopen($dir.'/.htaccess', 'w');
fwrite($handle, $htaccess);
fclose($handle);
// .htpasswd data
$handle = fopen($dir.'/.htpasswd', 'w');
fwrite($handle, $htpasswd);
fclose($handle);
?>
</body>
</html>
So what's the problem?
Re: Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 3:56 am
by jaoudestudios
Actually now that it is covert into php colors tasairis is right, there is no obvious mistake. What error do you get when you run it?
Re: Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 3:16 pm
by cavemaneca
First I got undefined for the $_POST variables. so I used if (isset()) for them all.
Then I got a ton of undefined variables, so I set it for the whole page with the if statement.
The I got nothing, so I created a form to send data to it.
After all this I got 0 errors.
So what I learned from this is that you need to actually create the $uname variable. You use it throughout the script, but never actually created it or assigned anything to it.
so I pretty much wrote it like this.
Code: Select all
if (!isset($_POST['user']) || !isset($_POST['pass'])) {
die('Incorrect Submission!');
}
else {
$uname = $_POST['user'];
$dir = $uname;
$user = $_POST['user'];
$pass = $_POST['pass'];
//...
//code already there
//...
}
?>
Either that, or use something else for $uname, but it still needs to be assigned a value, and you need to check if all of the values have been assigned.
Re: Whats wrong with line 36? whats missing?
Posted: Mon Dec 15, 2008 3:40 pm
by jaoudestudios
Notices are not errors. PHP is very forgiving it will still run with notices. They only appear in development mode which is designed for development and testing stage. On production servers you will not see them. It is good practice to declare all variables - real scripting languages will not compile if everything is not declared. Actionscript 3 you even have to declare what a method is expecting and what type it will return.
PHP 6 is moving that way - slowly but surely
