Member System, Made with XML and PHP, No MySQL

Discussion in 'Tutorials' started by dsihangout90, Apr 28, 2011.

  1. dsihangout90

    dsihangout90 New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello,
    Recently I found a very easy way to create a User Member System with using PHP,HTML,XML and No MySQL. Thought it would e nice to show you,

    STEP ONE: Making the Register Page.
    PHP:
    <?php
    $errors 
    = array();
    if(isset(
    $_POST['login'])){
        
    $username preg_replace('/[^A-Za-z]/'''$_POST['username']);
        
    $email $_POST['email'];
        
    $password $_POST['password'];
        
    $c_password $_POST['c_password'];
        
        if(
    file_exists('users/' $username '.xml')){
            
    $errors[] = 'Username already exists';
        }
        if(
    $username == ''){
            
    $errors[] = 'Username is blank';
        }
        if(
    $email == ''){
            
    $errors[] = 'Email is blank';
        }
        if(
    $password == '' || $c_password == ''){
            
    $errors[] = 'Passwords are blank';
        }
        if(
    $password != $c_password){
            
    $errors[] = 'Passwords do not match';
        }
        if(
    count($errors) == 0){
            
    $xml = new SimpleXMLElement('<user></user>');
            
    $xml->addChild('password'md5($password));
            
    $xml->addChild('email'$email);
            
    $xml->asXML('users/' $username '.xml');
            
    header('Location: compleat.php');
            die;
        }
    }
    ?>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>

    </head>
    <body>
        <font size=1>
        <form method="post" action="">
            <?php
            
    if(count($errors) > 0){
                echo 
    '<ul>';
                foreach(
    $errors as $e){
                    echo 
    '<li>' $e '</li>';
                }
                echo 
    '</ul>';
            }
            
    ?>
            <p>Username <input type="text" name="username" size="20" /></p>
            <p>Email <input type="text" name="email" size="20" /></p>
            <p>Password <input type="password" name="password" size="20" /></p>
            <p>Confirm Password <input type="password" name="c_password" size="20" /></p>
            <p><input type="submit" name="login" value="Register" /></p>
        </form>
    </body></font>
    </html>
    STEP TWO: The Login
    PHP:
    <?php
    $error 
    false;
    if(isset(
    $_POST['login'])){
        
    $username preg_replace('/[^A-Za-z]/'''$_POST['username']);
        
    $password md5($_POST['password']);
        if(
    file_exists('users/' $username '.xml')){
            
    $xml = new SimpleXMLElement('users/' $username '.xml'0true);
            if(
    $password == $xml->password){
                
    session_start();
                
    $_SESSION['username'] = $username;
                
    header('Location: index.php');
                die;
            }
        }
        
    $error true;
    }
    ?>
    <form method="post" action="">
            <p>Username <input type="text" name="username" size="20" /></p>
            <p>Password <input type="password" name="password" size="20" /></p>
            <?php
            
    if($error){
                echo 
    '<p>Invalid username and/or password</p>';
            }
            
    ?>
            <p><input type="submit" value="Login" name="login" /></p>
        </form>
    STEP THREE: The Settings Page (To change Passwords)
    PHP:
    <?php
    session_start
    ();
    if(!
    file_exists('users/' $_SESSION['username'] . '.xml')){
        
    header('Location: login.php');
        die;
    }
    $error false;
    if(isset(
    $_POST['change'])){
        
    $old md5($_POST['o_password']);
        
    $new md5($_POST['n_password']);
        
    $c_new md5($_POST['c_n_password']);
        
    $xml = new SimpleXMLElement('users/' $_SESSION['username'] . '.xml'0true);
        if(
    $old == $xml->password){
            if(
    $new == $c_new){
                
    $xml->password $new;
                
    $xml->asXML('users/' $_SESSION['username'] . '.xml');
                
    header('Location: logout.php');
                die;
            }
        }
        
    $error true;
    }

    ?>

    <head>
    </head>
    <body>
        <span style='text-shadow: 1 0 0 black;'><font size=2>Change Password:</span>
        <form method="post" action="">
            <?php 
            
    if($error){
                echo 
    '<p><u><h6>ERROR: A Password(s) has been typed Wrong! Try Again!</u></h6></p>';
            }
            
    ?>
            <p>Old password <input type="password" name="o_password" size=10 /></p>
            <p>New password <input type="password" name="n_password" size=10 /></p>
            <p>Confirm new password <input type="password" name="c_n_password" size=10 /></p>
            <p><input type="submit" name="change" value="Change Password" size=10 /></p>
        </form>
    <hr />
    <font size=1>IP Logged on you're Account: <span style='text-shadow: 1 0 0 black;'>
    <?
    $ip = getenv(REMOTE_ADDR);

    print "".$ip;

    ?></span>
    VERY IMPORTENT MAKE A FOLDER NAMMED "users" IF YOU DON'T NO USERS WILL BE ABLE TO LOGIN/REGISTERED. FOLDER USERS KEEPS THE LOGIN SCRIPTS THERE.

    Enjoy.

    ---------- Post added at 11:32 PM ---------- Previous post was at 11:27 PM ----------

    If theres any errors let me know and i'll fix them
     
  2. Sait Blun

    Sait Blun New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    how to upload file in php xml..can you help me??
     
  3. Linkz0rs

    Linkz0rs Member

    Messages:
    247
    Likes Received:
    7
    Trophy Points:
    18
    Don't forget to set things in the .htaccess file to prevent anyone from looking in the users directory.
     
  4. phoebex2

    phoebex2 Member

    Messages:
    55
    Likes Received:
    16
    Trophy Points:
    8
    I know this thread is kind of old, but thanks for posting your script. It makes me want to do something requiring it, just to have an excuse to mess with it.

    And I'm not just saying this as an excuse to post or something, databases are my Kryptonite, and your script is the sort of thing I'd be tempted to use if I made something involving signups.

    *saves the code*
     
  5. inadim8956

    inadim8956 Member

    Messages:
    107
    Likes Received:
    0
    Trophy Points:
    16
    Wow! I was thinking of doing this .. and here is the code :D .. I will definitely test it.
     
  6. studio5

    studio5 Member

    Messages:
    33
    Likes Received:
    2
    Trophy Points:
    8
    Looks like a great way to setup a user area without wasting a mysql; I really wish they would give us a few more of them......
     
  7. Zreddx

    Zreddx New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Could you make it so it would know who is logged in by saving their ip in their xml file (If many IP's they would all get added). This could make it possible to show who is logged in and have the change password thing on the settings page.
    Just a suggestion.
    Love your system
    - James
     

Share This Page