Results 1 to 9 of 9

Thread: Creating a login using CSV's

  1. #1
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default Creating a login using CSV's

    Is there a way to create a login system using a CSV table?
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

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

    Default

    That can be done the file operations supported by the PHP without much difficulty.

    I've done that once earlier but later changed that to database rather than using CSV.

    Quote Originally Posted by tech_support
    The CSV will be encrypted
    You mean the information stored in the CSV file or the file itself?

  3. #3
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have tried it once too. It gives a lot of pain when you need to update the values.

    Quote Originally Posted by codeexploiter
    Quote Originally Posted by tech_support
    The CSV will be encrypted
    You mean the information stored in the CSV file or the file itself?
    I don't think the OP ever posted that(at least I can't see that in the original post).

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Quote Originally Posted by codeexploiter
    I've done that once earlier but later changed that to database rather than using CSV.
    Quote Originally Posted by shachi
    I have tried it once too. It gives a lot of pain when you need to update the values.
    Can you give me the file? I could do it myself but I just haven't got the time.

    Quote Originally Posted by codeexpoliter
    You mean the information stored in the CSV file or the file itself?
    The information stored in the CSV file.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, here it is. It needs a little bit of tweaking(sorry I am a PHP newbie).

    login.php

    Code:
    <?php
    session_start();
    ?>
    <html>
    <head>
    </head>
    <body>
    <?php
    if(isset($_GET['login'])){
    if(isset($_SESSION['logged'])){
    echo 'You cannot login in when you are logged in already.';
    } else {
    ?>
    <form name="login" method="POST" action="processes.php">
    Username: <input type="text" name="username"><br>
    Password: <input type="password" name="password"><br>
    <input type="submit"><br>
    <a href="?register=true">Please Register Here</a>
    </form>
    <?php
    }
    } else if(isset($_GET['register'])){
    if(isset($_SESSION['logged'])){
    echo 'You cannot register when you are logged in.';
    } else {
    ?>
    <form name="login" method="POST" action="register.php">
    Username: <input type="text" name="username"><br>
    Password: <input type="password" name="password"><br>
    Email: <input type="text" name="email"><br>
    <input type="submit">
    </form>
    <?php
    }
    } else {
    if(isset($_SESSION['logged'])){
    echo 'You don\'t have any previleges here.';
    } else {
    ?>
    Please <a href="?login=true">Login</a><br>
    OR<br>
    Register <a href="?register=true">here</a>
    <?php
    }
    }
    ?>
    </body>
    </html>
    processes.php

    Code:
    <?php
    
    # function newfile, by Twey of dynamicdrive
    
    function newfile($filename){
    $lines = file($filename);
    $config = array();
    for($i = 1; $i < count($lines); ++$i)
    $config[substr($lines[$i], 0, strpos($lines[$i], ':'))] = substr($lines[$i], strpos($lines[$i], ':') + 1, -1); // -2 for a Windows host
    return $config;
    }
    if(isset($_GET['logout'])){
    unset($_SESSION['logged']);
    }
    //print_r(newfile('users.php'));
    $users = newfile('users.php');
    //echo $test['test1'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    list($pass,$email) = explode(',', $users[$username]);
    if(isset($users[$username]) && md5($password) == $pass){
    session_start();
    $_SESSION['logged'] = $username;
    echo 'Hello you are registered.<br>';
    echo 'Click <a href="somepage.php">here</a> to go to some other page.<br>';
    echo 'Click <a href="processes.php?logout=true">here</a> to logout.<br>';
    echo 'Your email address is '.$email;
    } elseif(!isset($users[$username]) && md5($password) != $users[$username]) {
    echo 'Username or password Incorrect';
    }
    if(isset($_SESSION['logged'])){
    echo '<br>test';
    }
    ?>
    register.php

    Code:
    <?php
    function newfile($filename){
    $lines = file($filename);
    $config = array();
    for($i = 1; $i < count($lines); ++$i)
    $config[substr($lines[$i], 0, strpos($lines[$i], ':'))] = substr($lines[$i], strpos($lines[$i], ':') + 1, -1); // -2 for a Windows host
    return $config;
    }
    $users = newfile('users.php');
    $user = $_POST['username'];
    $pass = md5($_POST['password']);
    $email = $_POST['email'];
    if(isset($user) && isset($pass)){
    if(array_key_exists($user, $users)){
    echo 'Username Taken';
    } else {
    $f = fopen('users.php', 'a');
    fwrite($f, $user.":".$pass.",".$email."\n");
    fclose($f);
    echo 'Successfully registered!!! Please click here to login.<br><a href="login.php?login=true">Login</a>';
    }
    } else {
    echo 'No Username or password';
    }
    ?>
    somepage.php

    Code:
    <?php
    session_start();
    if(isset($_SESSION['logged'])){
    echo 'You are still logged in';
    echo '<br><a href="processes.php?logout=true">Logout</a>';
    } else {
    echo 'Please login first';
    }
    ?>
    users.php

    Code:
    <?php exit();?>
    Hope it helps!!
    Last edited by shachi; 11-25-2006 at 01:14 PM.

  6. #6
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Yep, That's exactly what I wanted. Thanks!
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  7. #7
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You're welcome. By the way the newfile function is by Twey so I would be grateful if you could place the notice intact.
    Last edited by shachi; 11-25-2006 at 01:15 PM.

  8. #8
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Just noticed that. Ok
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  9. #9
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot.

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
  •