Foros del Web » Programando para Internet » PHP »

Error codigo proteccion página php

Estas en el tema de Error codigo proteccion página php en el foro de PHP en Foros del Web. Ante todo saludar a todos, pues es de rigor. Tengo un codigo en php para proteger una pagina con usuario y contraseña, esta hecho sin ...
  #1 (permalink)  
Antiguo 31/01/2011, 02:15
Avatar de manyblue  
Fecha de Ingreso: marzo-2008
Mensajes: 329
Antigüedad: 16 años
Puntos: 10
Error codigo proteccion página php

Ante todo saludar a todos, pues es de rigor.

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=0error($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=1error($notice); }
// If the log in was sucessful
else if (strcmp($namePassCombos[$loginName],$passWord) == 0) { success($logSuccess,$logInTracker,$loginName,$goHere); }
?>
Es decir, Un enlace de una zona de la pagina nos lleva a un formulario de login con user y pass, se mete el user y pass y si es correcto me va a la pagina restringida, muy sencillo.

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
  #2 (permalink)  
Antiguo 31/01/2011, 05:19
Avatar de Heli0s  
Fecha de Ingreso: abril-2010
Mensajes: 789
Antigüedad: 14 años
Puntos: 40
Respuesta: Error codigo proteccion página php

El problema es que no encuentra el archivo, y eso desencadena todos los errores. ¿Estás seguro que usas la misma estructuras de directorios en tus servidores y que hay un archivo succesLog.txt en la carpeta files?
  #3 (permalink)  
Antiguo 31/01/2011, 05:55
Avatar de manyblue  
Fecha de Ingreso: marzo-2008
Mensajes: 329
Antigüedad: 16 años
Puntos: 10
Respuesta: Error codigo proteccion página php

Cita:
Iniciado por Heli0s Ver Mensaje
El problema es que no encuentra el archivo, y eso desencadena todos los errores. ¿Estás seguro que usas la misma estructuras de directorios en tus servidores y que hay un archivo succesLog.txt en la carpeta files?
Que archivo es el que no encuentra ???
Como podria solucionarlo ???
Por que en 1and1 (servidor externo) si funciona y no me da errores ???

Muchiiiiiiiisimas gracias de antemano, manyblue
  #4 (permalink)  
Antiguo 31/01/2011, 05:57
Avatar de AdrianSeg  
Fecha de Ingreso: enero-2010
Mensajes: 595
Antigüedad: 14 años, 2 meses
Puntos: 14
Respuesta: Error codigo proteccion página php

No se encuentra este:

Warning: fopen(files/successLog.txt)

Si en otro server te funciona una de dos, o oculta los errores automaticamente o tienes la estructura correcta.
  #5 (permalink)  
Antiguo 31/01/2011, 05:58
Avatar de manyblue  
Fecha de Ingreso: marzo-2008
Mensajes: 329
Antigüedad: 16 años
Puntos: 10
Respuesta: Error codigo proteccion página php

Cita:
Iniciado por manyblue Ver Mensaje
Que archivo es el que no encuentra ???
Como podria solucionarlo ???
Por que en 1and1 (servidor externo) si funciona y no me da errores ???

Muchiiiiiiiisimas gracias de antemano, manyblue
si uso la misma estructura, es decir, esta web la tengo en mi portatil con wampserver y funciona bien, la subo exactamente igual con filezilla a 1and1 y funciona perfectamente, la subo exactamente igual a mi server con freeBSD y me da estos errores.

muchisimas gracias de antemano
  #6 (permalink)  
Antiguo 31/01/2011, 06:03
Avatar de AdrianSeg  
Fecha de Ingreso: enero-2010
Mensajes: 595
Antigüedad: 14 años, 2 meses
Puntos: 14
Respuesta: Error codigo proteccion página php

Prueba con una ruta absoluta:

www.tuweb.com



Código PHP:
Ver original
  1. $log=fopen("www.tuweb.com/files/$logInTracker", "a+");

Aunque no sé si te dejará.
  #7 (permalink)  
Antiguo 31/01/2011, 06:05
Avatar de manyblue  
Fecha de Ingreso: marzo-2008
Mensajes: 329
Antigüedad: 16 años
Puntos: 10
Respuesta: Error codigo proteccion página php

Cita:
Iniciado por manyblue Ver Mensaje
si uso la misma estructura, es decir, esta web la tengo en mi portatil con wampserver y funciona bien, la subo exactamente igual con filezilla a 1and1 y funciona perfectamente, la subo exactamente igual a mi server con freeBSD y me da estos errores.

muchisimas gracias de antemano
JAJAJAAJAJAJAJ tienes razon veo que en mi portatil con wampserver el solito ha creado el archivo:

successLog.txt:

Código:
 
est logged in on: Monday 31st 2011f January 2011 11:50:12 AM - Logged IP address: 127.0.0.1
Que es lo que hago, subo este archivo .txt al server tambien ?????

muchisimas gracias de antemano
  #8 (permalink)  
Antiguo 31/01/2011, 06:07
 
Fecha de Ingreso: agosto-2009
Mensajes: 34
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: Error codigo proteccion página php

verifica los permisos de acceso a la carpeta donde almacenas los archivos
  #9 (permalink)  
Antiguo 31/01/2011, 06:12
Avatar de AdrianSeg  
Fecha de Ingreso: enero-2010
Mensajes: 595
Antigüedad: 14 años, 2 meses
Puntos: 14
Respuesta: Error codigo proteccion página php

Si, sube le archivo al servidor dentro de files.
  #10 (permalink)  
Antiguo 31/01/2011, 06:28
Avatar de manyblue  
Fecha de Ingreso: marzo-2008
Mensajes: 329
Antigüedad: 16 años
Puntos: 10
Respuesta: Error codigo proteccion página php

Cita:
Iniciado por AdrianSeg Ver Mensaje
Prueba con una ruta absoluta:

www.tuweb.com



Código PHP:
Ver original
  1. $log=fopen("www.tuweb.com/files/$logInTracker", "a+");

Aunque no sé si te dejará.

Bueno primero subi el archivo .txt al server probe y me salen estos errores:

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /usr/local/www/apache22/data/spa/dataProcess.php on line 29

Warning: fopen(successLog.txt) [function.fopen]: failed to open stream: Permission denied in /usr/local/www/apache22/data/spa/dataProcess.php on line 36

Warning: fputs() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 37

Warning: fclose() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/apache22/data/spa/dataProcess.php:29) in /usr/local/www/apache22/data/spa/dataProcess.php on line 42

Luego varie dataProcess.php asi:


Código PHP:
// 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("manyblue.homeunix.com/spa/files/$logInTracker""a+");
       
fputs($log"$loginName logged in on: $date - Logged IP address: $ip\n");
  
fclose($log);
 } 


y me da los siguientes errores


Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /usr/local/www/apache22/data/spa/dataProcess.php on line 29

Warning: fopen(manyblue.homeunix.com/spa/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 36

Warning: fputs() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 37

Warning: fclose() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/apache22/data/spa/dataProcess.php:29) in /usr/local/www/apache22/data/spa/dataProcess.php on line 42


Sinceramente no se por que no funciona en mi server y en los externos si.
Muchisimas gracias de antemano
  #11 (permalink)  
Antiguo 31/01/2011, 06:43
Avatar de manyblue  
Fecha de Ingreso: marzo-2008
Mensajes: 329
Antigüedad: 16 años
Puntos: 10
Respuesta: Error codigo proteccion página php

probe eliminando esta parte de dataProcess.php

Código PHP:
       // 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);
    } 
Me da menos errores pero me los sigue dando:



Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /usr/local/www/apache22/data/spa/dataProcess.php on line 29

Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/apache22/data/spa/dataProcess.php:29) in /usr/local/www/apache22/data/spa/dataProcess.php on line 37
  #12 (permalink)  
Antiguo 31/01/2011, 07:00
 
Fecha de Ingreso: enero-2007
Mensajes: 146
Antigüedad: 17 años, 2 meses
Puntos: 16
Respuesta: Error codigo proteccion página php

Cita:
Iniciado por manyblue Ver Mensaje
Bueno primero subi el archivo .txt al server probe y me salen estos errores:

Warning: date() [[URL="http://manyblue.homeunix.com/spa/function.date"]function.date[/URL]]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /usr/local/www/apache22/data/spa/dataProcess.php on line 29

Warning: fopen(successLog.txt) [[URL="http://manyblue.homeunix.com/spa/function.fopen"]function.fopen[/URL]]: failed to open stream: Permission denied in /usr/local/www/apache22/data/spa/dataProcess.php on line 36

Warning: fputs() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 37

Warning: fclose() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/apache22/data/spa/dataProcess.php:29) in /usr/local/www/apache22/data/spa/dataProcess.php on line 42

Luego varie dataProcess.php asi:


Código PHP:
// 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("manyblue.homeunix.com/spa/files/$logInTracker""a+");
       
fputs($log"$loginName logged in on: $date - Logged IP address: $ip\n");
  
fclose($log);
 } 


y me da los siguientes errores


Warning: date() [[URL="http://manyblue.homeunix.com/spa/function.date"]function.date[/URL]]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /usr/local/www/apache22/data/spa/dataProcess.php on line 29

Warning: fopen(manyblue.homeunix.com/spa/files/successLog.txt) [[URL="http://manyblue.homeunix.com/spa/function.fopen"]function.fopen[/URL]]: failed to open stream: No such file or directory in /usr/local/www/apache22/data/spa/dataProcess.php on line 36

Warning: fputs() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 37

Warning: fclose() expects parameter 1 to be resource, boolean given in /usr/local/www/apache22/data/spa/dataProcess.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at /usr/local/www/apache22/data/spa/dataProcess.php:29) in /usr/local/www/apache22/data/spa/dataProcess.php on line 42


Sinceramente no se por que no funciona en mi server y en los externos si.
Muchisimas gracias de antemano
Ahí te está diciendo que no tienes permisos en el fichero. Dale un 0777 para poder escribir con cualquier usuario :)
  #13 (permalink)  
Antiguo 01/02/2011, 05:19
Avatar de manyblue  
Fecha de Ingreso: marzo-2008
Mensajes: 329
Antigüedad: 16 años
Puntos: 10
Respuesta: Error codigo proteccion página php

OK entrare en el server (freeBSD) y le dare permisos

# chmod 777 dataProcess.php

ya te contare como me fue, como siempre muchiiiiiiisimas gracias por tu atencion.
manyblue

Etiquetas: proteccion
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:49.