Results 1 to 4 of 4

Thread: fopen, rewind, and feof errors

  1. #1
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default fopen, rewind, and feof errors

    I am getting this error:
    Code:
    Warning: fopen(_users/admin/userpwd.php) [function.fopen]: failed to open stream: No such file or directory in C:\wamp\www\login\common.php on line 14
    
    Warning: rewind(): supplied argument is not a valid stream resource in C:\wamp\www\login\common.php on line 15
    
    Warning: feof(): supplied argument is not a valid stream resource in C:\wamp\www\login\common.php on line 17
    
    Warning: fgets(): supplied argument is not a valid stream resource in C:\wamp\www\login\common.php on line 18
    Here is the Code: I think it has something to do with the rewind().... Anyone know a fix?
    PHP Code:
    <?php

    session_start
    ();

    function 
    registerUser($user,$pass1,$pass2){
        
    $errorText '';
        
        
    // Check passwords
        
    if ($pass1 != $pass2$errorText "Passwords are not identical!";
        elseif (
    strlen($pass1) < 6$errorText "Password is to short!";
        
        
    // Check user existance    
        
    $pfile fopen("_users/" $user "/details.php","a+");
        
    rewind($pfile);

        while (!
    feof($pfile)) {
            
    $line fgets($pfile);
            
    $tmp explode(':'$line);
            if (
    $tmp[0] == $user) {
                
    $errorText "Sorry, the selected user name is taken!";
                break;
            }
        }
        
        
    // If everything is OK -> store user data
        
    if ($errorText == ''){
            
    // Secure password string
            //$userpass = md5($pass1);
            
    $userpass $pass1;
            
            
    fwrite($pfile"\r\n$user:$userpass");
        }
        
        
    fclose($pfile);
        
        
        return 
    $errorText;
    }

    function 
    loginUser($user,$pass){
        
    $errorText '';
        
    $validUser false;
        
        
    // Check user existance    
        
    $pfile fopen("_users/" $user "/details.php","r");
        
    rewind($pfile);

        while (!
    feof($pfile)) {
            
    $line fgets($pfile);
            
    $tmp explode(':'$line);
            if (
    $tmp[0] == $user) {
                
    // User exists, check password
                
    if (trim($tmp[1]) == trim($pass)){
                    
    $validUsertrue;
                    
    $_SESSION['userName'] = $user;
                }
                break;
            }
        }
        
    fclose($pfile);

        if (
    $validUser != true$errorText "Invalid username or password!";
        
        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: login.php');
        }
    }

    ?>

  2. #2
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    here is the new code:
    PHP Code:
    <?php

    session_start
    ();

    function 
    registerUser($user,$pass1,$pass2){
        
    $errorText '';
        
        
    // Check passwords
        
    if ($pass1 != $pass2$errorText "Passwords are not identical!";
        elseif (
    strlen($pass1) < 6$errorText "Password is to short!";
        
            
    // Secure password string
            //$userpass = md5($pass1);
            
    $userpass $pass1;
            
        
    // Check user existance    
        
      
    $userDir "_users/" $user;
      
    $filename $userDir "/config.php";
      
    $open fopen($filename'w+');
      
    $data "Jane Doe\n";
      
    fwrite($open$data);

        if (
    is_dir($userDir)) {
        echo (
    "Sorry, but the username is taken.");  
        }
        else
        {
        
    //fwrite($userDir . $filename, "$user:$userpass"); 
        
    fwrite($open$data);
        }
       
          
    fclose($open);
        
        
        return 
    $errorText;
    }

    function 
    loginUser($user,$pass){
        
    $errorText '';
        
    $validUser false;
        
        
    // Check user existance    
        
    $userDir fopen("_users/" $user "/details.php","r");
        
    rewind($userDir);

        while (!
    feof($userDir)) {
            
    $line fgets($userDir);
            
    $tmp explode(':'$line);
            if (
    $tmp[0] == $user) {
                
    // User exists, check password
                
    if (trim($tmp[1]) == trim($pass)){
                    
    $validUsertrue;
                    
    $_SESSION['userName'] = $user;
                }
                break;
            }
        }
        
    fclose($userDir);

        if (
    $validUser != true$errorText "Invalid username or password!";
        
        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: login.php');
        }
    }

    ?>

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I think not all the stream are seekable using rewind/fseek. But i think you can find some method to make a stream seekable in http://www.php.net website.

  4. #4
    Join Date
    Mar 2006
    Posts
    600
    Thanks
    5
    Thanked 4 Times in 4 Posts

    Default

    yes, i fixed it last night. Thanks though.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •