Tengo un codigo en php para proteger una pagina con usuario y contraseña, esta hecho sin mysql pues como es para una sola persona no necesito mas.
El codigo es el siguiente:
Código PHP:
<?php
$goHere="personal.php"; // Page to send successfull log-ins to
$logSuccess="1"; // Track / log successful log-ins (1 = yes and 0 = no)
$namePassCombos = array ( // Add as many lines as you like below
"test" => "123456" // Add username and password combo here
);
// Multiple user Log-In script by Dave Lauderdale - Originally published at: www.digi-dl.com
// The below code may or may not be necessary for you
$loginName = $_POST['loginName']; $passWord = $_POST['passWord'];
// Replace bad characters in user input
$passWord = preg_replace ("/</","[",$passWord); $loginName = preg_replace ("/>/","]",$loginName);
$loginName = str_replace(".."," ",$loginName); $passWord = str_replace(".."," ",$passWord);
// Trim whitespace from user input
$loginName=trim($loginName); $passWord=trim($passWord);
// If log-in was successfull
$logInTracker="successLog.txt";
function success($logSuccess,$logInTracker,$loginName,$goHere)
{
$date=date ("l dS of F Y h:i:s A");
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) $ip = getenv(REMOTE_ADDR);
else $ip = $_SERVER['REMOTE_ADDR'];
// If webmaster wants to log successful logins
if($logSuccess=="1"){
$log=fopen("files/$logInTracker", "a+");
fputs($log, "$loginName logged in on: $date - Logged IP address: $ip\n");
fclose($log);
}
// If no log or after log then go here
Header("Location: $goHere");
}
// If there is an error
function error($notice)
{
// Display error notice (0)
if($notice=="0"){
echo"
<title>Log-In Error: Absent username / password</title>
<body><br><p style=\"font:11pt arial\"><font color=red>NOTICE:</font> Log-In Error: Absent username / password.
<br><br><br>Click <a href=\"javascript:history.back(1)\" style=\"color:black\">here</a> to try again.
</body></html>
"; exit;
}
// Display error notice (1)
if($notice=="1"){
echo"
<title>Log-In Error: Incorrect username / password</title>
<body><br><p style=\"font:11pt arial\"><font color=red>NOTICE:</font> Log-In Error: Incorrect username / password.
<br><br><br>Click <a href=\"javascript:history.back(1)\" style=\"color:black\">here</a> to try again.
</body></html>
"; exit;
}
}
// If the user doesnt enter a name or password then set error notice to 0 and display error
if (($loginName == "") || ($passWord == "")) { $notice=0; error($notice); }
// If the username and password entered don't match then set error notice to 1 and display error
else if (strcmp($namePassCombos[$loginName],$passWord) != 0) { $notice=1; error($notice); }
// If the log in was sucessful
else if (strcmp($namePassCombos[$loginName],$passWord) == 0) { success($logSuccess,$logInTracker,$loginName,$goHere); }
?>
Mi problema:
Si subo esto a un server externo no me da ningun problema, por ejemplo arsys o 1 and 1, pero cuando lo subo a mi server privado que esta en FreeBSD me dan estos errores:
Warning: fopen(files/successLog.txt) [function.fopen]: failed to open stream: No such file or directory in /usr/local/www/apache22/data/spa/dataProcess.php on line 37
Warning: fputs() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 38
Warning: fclose() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 39
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/apache22/data/spa/dataProcess.php:37) in /usr/local/www/apache22/data/spa/dataProcess.php on line 43
La verdad es que no se que me esta pasando en mi server, podriasis ayudarme, creis que solucion pasa por restructurar el codigo ?
las lineas en concreto son:
35 if($logSuccess=="1"){
36 $log=fopen("files/$logInTracker", "a+");
37 fputs($log, "$loginName logged in on: $date - Logged IP address: $ip\n");
38 fclose($log);
39 }
43 Header("Location: $goHere");
}
Muchisimas gracias de antemano