Results 1 to 7 of 7

Thread: adding new user and create directory for each user

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    sorry it same proble php script

    Hi everyone
    I am bit stress I did for got to post the code last time I do apologise
    I tried to create script to register user by storing their information in a text file and create directory for each one, no be noted I did crate the text file but nothing on it in but doesn't work without any error occurred I did checked the file sill empty despite storing some new user. Could any help please? With many thanks.


    <html>
    <title>Registration</title>
    </head>

    <body>
    <fieldset>
    <?php include "header.php"; ?>
    <h3>Please type your details</h3>

    <?php /*script to handle and display HTML form also register user by storing
    their information in a text file and create a directory for them*/

    //handle the form
    if (isset ($_post['submit']))
    {

    $problem = false;//boolean to chack a state of problem or not, initialised to false
    // no problem

    // check username value of the form
    if (empty($_post['username']))
    {
    $problem = true;
    print '<p> Please enter your name</p>';
    }

    // check validation of entered password (confirmation)
    if (empty($_post['password1']))
    {
    $problem = true;
    print '<p> Please enter a password</p>';
    }
    // check validation of entered password (confirmation)
    if ($_post['password1'] != $_post['password2'])
    {
    $problem = true;
    print '<p> Your password not match confirmed password</p>';
    }


    // check if there weren't any problem
    if(!$problem)
    {
    // open the file
    if($fp = fopen('../users/users.txt', 'a+'))
    {
    //create the data to be written and close the file.
    $dir = time () . rand(0,4596);
    $data= $_post['username'] . "\t" . crypt($_post['password1']) . "\t"

    .$dir . "\r\n";

    //write data to and close the file.
    fwrite($fp,$data);

    fclose($fp);

    // create the directory
    mdir('../users/$dir');

    // print a meessage
    print '<p> You are registered</p>';
    }

    // forgot a field
    else
    {
    print '<p> Please try again</p>';
    }

    }
    else
    {// could not write to the file

    //print '<p><you could not be registered due to system error</p>';
    }
    }
    // display the form
    else
    {
    ?>

    <form action="new.php" method ="post">

    Username <input type = "text" name ="username" size ="20"><br/>

    Password <input type = "password" name ="password1" size ="20"><br/>

    Confirm Password <input type = "password" name ="password2" size ="20"><br/>

    <input type = "submit" name ="submit" value = "Register"><br/>
    </fieldset>
    </form>
    <?php
    }// end of submit if
    ?>

    </body>
    </html>

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: sorry it same proble php script

    If you forget something you can always use the Edit Post button () to add anything as necessary.

    Also, please remember use the [php]...[/php] tags when posting code.

  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: sorry it same proble php script

    well, that won't work because you are calling mdir() instead of mkdir(). mdir() is not a function.

    you should really, really, really consider putting some custom error checks in different places -- and you need to look at your web server's log files when an error occurs to see what's going on (if you have errors suppressed). these are simple problems; and we're not here to do everything for you. you should be learning as you go along, too. you still haven't learned to use the [php] tags ;)

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    adding new user and create directory for each user

    Hi thanks mate for reply, could you tell me what wrong please, I did create folder called users in the web rooter and user.txt inside the user folder. With many thanks


    PHP Code:
    <html>
    <title>Registration</title>
    </head>

    <body>
    <fieldset>
    <?php include "header.php"?>
    <h3>Please type your details</h3>

    <?php  /*script to handle and display HTML form also register user by storing 
         their information in a text file and create a directory for them*/

    //handle the form
    if (isset ($_post['submit']))
    {
            
        
    $problem false;//boolean to chack a state of problem or not, initialised to false 
                // no problem
        
        // check username value of the form
        
    if (empty($_post['username']))
        {
            
    $problem true;
            print 
    '<p> Please enter your name</p>';
        }
        
        
    // check validation of entered password (confirmation)
        
    if (empty($_post['password1']))
        {
            
    $problem true;
                    print 
    '<p> Please enter a password</p>';
        }
        
    // check validation of entered password (confirmation)
            
    if ($_post['password1'] !=  $_post['password2'])
        {
            
    $problem true;
                    print 
    '<p> Your password  not match  confirmed password</p>';
        }
        
            
        
    // check if there weren't any problem
        
    if(!$problem)
        {
            
    // open the file 
            
    if($fp fopen('/users/users.txt''a+'))
            {
                
    //create the data to be written and close the file.
                
    $dir usersname
                
    $data$_post['username'] . "\t" crypt($_post['password1']) . "\t" .$dir "\r\n";
                
                
    //write data to  and close the file.
                
    fwrite($fp,$data);
                
                
    fclose($fp);
                
                
    // create the directory
                
    mkdir('/users/username');
                
            }
            else
            {
                
    '<p> Please try again</p>';
                
    // print a meessage 
                
    print '<p> You are registered</p>';
            }
        }
        else
        {
    // could not write to the file 
                
                //print '<p><you could not be registered due to system error</p>';
        
    }
    }
    // display the form
    else
    {
    ?>

    <form action="new.php" method ="post">

    Username <input type = "text" name ="username" size ="20"><br/>

    Password <input type = "password" name ="password1" size ="20"><br/>

    Confirm Password <input type = "password" name ="password2" size ="20"><br/>

    <input type = "submit" name ="submit" value = "Register"><br/>
    </fieldset>
    </form>
    <?php
    }// end of submit if 
    ?>
     
    </body>
    </html>

  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: adding new user and create directory for each user

    what is the purpose of having a file with all the usernames? Why not Use a database backend?
    My usual boring signature: Something

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: adding new user and create directory for each user

    Threads merged as I think you hit New Thread instead of Post Reply.

  7. #7
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: adding new user and create directory for each user

    you have a string in the middle of no where. you need to use either echo or print. also, you shouldn't have that 'you successfully registered' string there. obviously, they aren't registered if they're getting an error message.
    PHP Code:
            }
            else
            {
                
    '<p> Please try again</p>';
                
    // print a meessage 
                
    print '<p> You are registered</p>';
            } 

    you're defining a variable to a constant that doesn't exist.
    PHP Code:
                $dir usersname
    you should be looking over your own code for these simple types of errors before posting.

    edit: oh, and someone would use a text file when they don't have a database available, or need to create a file that can be imported or used by another program (that doesn't support databases). besides, text files are the oldest form of databases -- they're just horrendously slow for any practical applications.
    Last edited by kows; Apr 25th, 2007 at 09:56 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width