newbe123 Posted November 23, 2010 Share Posted November 23, 2010 I have created a login page where you can register, log in and log out. Here everything is saved on file (not MySQL or other databases). Everything works fine when I tested this in http://localhost/ but when I upload everything to a Web server, so that you can access them from "outside" then I get lots of error such as Warning: fopen(userpwd.txt) [function.fopen]: failed to open stream: Permission denied in /afs/ltu.se/systemdata/www/students/somroy-0/gemensam.php on line 13 what can I do to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/ Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 failed to open stream: Permission denied did you set the permissions on the file to allow apache/PHP to read the file? Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138675 Share on other sites More sharing options...
newbe123 Posted November 23, 2010 Author Share Posted November 23, 2010 I am so new with all of this. This is what I've done. gemensam.php (common.php in English) <?php session_start(); function registerUser($user,$pass1,$pass2){ $errorText = ''; // Kontrollera lösenord if ($pass1 != $pass2) $errorText = "Lösenorden är inte identiska!"; elseif (strlen($pass1) < 6) $errorText = "Lösenordet är för kort!"; // Kontrollera om användare redan existerar $pfile = fopen("userpwd.txt","a+"); rewind($pfile); while (!feof($pfile)) { $line = fgets($pfile); $tmp = explode(':', $line); if ($tmp[0] == $user) { $errorText = "Användarnamnet finns redan!"; break; } } // Om allt är OK -> lagra användardata if ($errorText == ''){ // Säkera lösenord sträng $userpass = md5($pass1); fwrite($pfile, "\r\n$user:$userpass"); } fclose($pfile); return $errorText; } function loginUser($user,$pass){ $errorText = ''; $validUser = false; // Kontrollera användare existerar $pfile = fopen("userpwd.txt","r"); rewind($pfile); while (!feof($pfile)) { $line = fgets($pfile); $tmp = explode(':', $line); if ($tmp[0] == $user) { // Användaren finns, kolla lösenord if (trim($tmp[1]) == trim(md5($pass))){ $validUser= true; $_SESSION['userName'] = $user; } break; } } fclose($pfile); if ($validUser != true) $errorText = "Ogiltigt användarnamn eller lösenord!"; if ($validUser == true) $_SESSION['validUser'] = true; else $_SESSION['validUser'] = false; return $errorText; } function logoutUser(){ unset($_SESSION['validUser']); unset($_SESSION['userName']); } function checkUser(){ if ((!isset($_SESSION['validUser'])) || ($_SESSION['validUser'] != true)){ header('Location: loggain.php'); } } ?> Loggain.php (login.php in English) <?php require_once('gemensam.php'); $error = '0'; if (isset($_POST['submitBtn'])){ // Inmatning $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; // Försök att logga in användaren $error = loginUser($username,$password); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Inloggningssystem</title> <link rel="stylesheet" type="text/css" href="stilmall.css" /> </head> <body> <?php if ($error != '') {?> <h1>Inloggning</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="loginform"> <p> Användarnamn: <br /><input class="text" name="username" type="text" /><br /><br /> Lösenord:<br /> <input class="text" name="password" type="password" /><br /><br /> <input class="text" type="submit" name="submitBtn" value="Login" /> </p> </form> <a href="registrera.php">Registrera</a> <?php } if (isset($_POST['submitBtn'])){ ?> Resultat:</br> <?php if ($error == '') { echo "Welcome $username! <br/>Du är nu inloggad!<br/><br/>"; echo '<a href="loggaut.php">Logga ut!</a>'; } ?> <?php } ?> </body> Registrera.php ( register.php in English) <?php require_once('gemensam.php'); if (isset($_POST['submitBtn'])){ // Get user input $username = isset($_POST['username']) ? $_POST['username'] : ''; $password1 = isset($_POST['password1']) ? $_POST['password1'] : ''; $password2 = isset($_POST['password2']) ? $_POST['password2'] : ''; // Try to register the user $error = registerUser($username,$password1,$password2); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Inloggningssystem</title> <link rel="stylesheet" type="text/css" href="stilmall.css" /> </head> <body> <h1>Lägg till användare</h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="registerform"> <p> Användarnamn:<br /> <input class="text" name="username" type="text" /><br /><br /> Lösenord:<br /> <input class="text" name="password1" type="password" /><br /><br /> Bekräfta lösenord:<br /><input class="text" name="password2" type="password" /><br /><br /> <input class="text" type="submit" name="submitBtn" value="Register" /> </p> </form> <a href="loggain.php">Logga in om du redan är registrerad</a><br /><br /> <?php if ((!isset($_POST['submitBtn'])) || ($error != '')) { ?> <?php } if (isset($_POST['submitBtn'])){ ?> Resultat:<br /> <?php if ($error == '') { echo " Användare: $username har registrerats!<br/><br/>"; echo ' <a href="loggain.php">Logga in här</a>'; } else echo $error; ?> <?php } ?> </body> loggaut.php (logout.php in English) <?php require_once('gemensam.php'); logoutUser(); header('Location: loggain.php'); ?> This is all so new to me and I am doing it but don't know what I'm doing! Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138688 Share on other sites More sharing options...
newbe123 Posted November 23, 2010 Author Share Posted November 23, 2010 how can I fix this. Help please Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138726 Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 Warning: fopen(userpwd.txt) [function.fopen]: failed to open stream: Permission denied the problem is probably with the permissions on the file userpwd.txt. you need to update the permissions on that file so that your script can open it. using an ftp program or other, set the permissions on the file to 777. chmod 777. Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138730 Share on other sites More sharing options...
newbe123 Posted November 23, 2010 Author Share Posted November 23, 2010 I did that but still it does not work! Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138747 Share on other sites More sharing options...
BlueSkyIS Posted November 23, 2010 Share Posted November 23, 2010 try using the full path to userpwd.txt. it may be this: $pfile = fopen($_SERVER['DOCUMENT_ROOT']."/userpwd.txt","a+"); Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138756 Share on other sites More sharing options...
newbe123 Posted November 23, 2010 Author Share Posted November 23, 2010 no it did not work and this is what I get Warning: fopen(/data/apache/www/userpwd.txt) [function.fopen]: failed to open stream: Permission denied in /afs/ltu.se/systemdata/www/students/somroy-0/gemensam.php on line 13 Warning: rewind(): supplied argument is not a valid stream resource in /afs/ltu.se/systemdata/www/students/somroy-0/gemensam.php on line 14 Warning: feof(): supplied argument is not a valid stream resource in /afs/ltu.se/systemdata/www/students/somroy-0/gemensam.php on line 16 Warning: fgets(): supplied argument is not a valid stream resource in /afs/ltu.se/systemdata/www/students/somroy-0/gemensam.php on line 17 Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138761 Share on other sites More sharing options...
newbe123 Posted November 24, 2010 Author Share Posted November 24, 2010 Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138770 Share on other sites More sharing options...
newbe123 Posted November 24, 2010 Author Share Posted November 24, 2010 I really really need help with this . anyone Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138781 Share on other sites More sharing options...
Pikachu2000 Posted November 24, 2010 Share Posted November 24, 2010 Don't bump threads so quickly unless you have new information to add. Quote Link to comment https://forums.phpfreaks.com/topic/219629-error-problem-php-help/#findComment-1138784 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.