Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14280

Re: Php login/registration page

From Matthew Carter <m@ahungry.com>
Newsgroups comp.lang.php
Subject Re: Php login/registration page
Date 2014-10-03 00:24 -0400
Organization Ahungry (http://ahungry.com)
Message-ID <87ppe9vl0e.fsf@ahungry.com> (permalink)
References (1 earlier) <m0fjdl$64d$1@dont-email.me> <ECKWv.296304$Q61.224596@fx13.iad> <m0gr5h$b0m$1@dont-email.me> <XnsA3BB1AEBFA590R2D2@127.0.0.1> <m0l577$4et$2@dont-email.me>

Show all headers | View raw


While everything said so far is true, I think its all a bit
overkill for what was likely intended as a simple exercise in teaching
novice users the very basics of a registration/sign in processes (which
is something a new programmer can relate to and understand a lot more
than security considerations).

I'd think the intention of a non-database registration page would be a
page where the user fills out a form and the data posted writes to a
flat file (which is then subsequently read from for confirming a user is
registered, to access a single member only page).

Something like the following (insecure registration code follows - do
not really use this code):

<?php
function register()
{
  if(empty($_POST['id']) || empty($_POST['pass']))
    {
      throw new Exception('Both id and pass are required fields.');
    }

  $file = '/tmp/user-data';

  if(!file_exists($file))
    {
      file_put_contents($file, '');
    }

  $users = unserialize(file_get_contents($file));

  if(isset($users[$_POST['id']]))
    {
      throw new Exception(
        'That user name is already taken, please choose another!');
    }

  $users[$_POST['id']] = $_POST['pass'];
  file_put_contents($file, serialize($users));

  printf("Thank you for registering %s", $_POST['id']);
}

$err = '';

if(!empty($_POST))
  {
    try
      {
        register();
      }
    catch(Exception $e)
      {
        $err = $e->getMessage();
      }
  }
?>
<!DOCTYPE html>
<html>
  <head>
    <title>Registration</title>
  </head>
  <body>
    <span style="color:red;"><?php echo $err;?></span>
    <form name='reg' method='post' action=''>
      User: <input type='text' value='' name='id'>
      Pass: <input type='password' value='' name='pass'>
      <input type='submit'>
    </form>
  </body>
</html>

-- 
Matthew Carter (m@ahungry.com)
http://ahungry.com

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Php login/registration page Apple Sizat <afor6993@gmail.com> - 2014-09-30 16:04 -0700
  Re: Php login/registration page Jerry Stuckle <jstucklex@attglobal.net> - 2014-09-30 20:55 -0400
    Re: Php login/registration page Richard Damon <Richard@Damon-Family.org> - 2014-09-30 23:33 -0400
      Re: Php login/registration page "J.O. Aho" <user@example.net> - 2014-10-01 06:51 +0200
      Re: Php login/registration page Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-01 08:13 -0400
        Re: Php login/registration page Richard Damon <Richard@Damon-Family.org> - 2014-10-01 22:37 -0400
        Re: Php login/registration page GS <nomail@nospam.org.invalid> - 2014-10-03 01:38 +0000
          Re: Php login/registration page Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-02 21:43 -0400
          Re: Php login/registration page Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-03 03:29 +0000
            Re: Php login/registration page Matthew Carter <m@ahungry.com> - 2014-10-03 00:24 -0400
              Re: Php login/registration page Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-03 18:33 +0000
                Re: Php login/registration page Matthew Carter <m@ahungry.com> - 2014-10-03 16:16 -0400
                Re: Php login/registration page Ed Mullen <ejEVOMER@edmullen.net> - 2014-10-03 18:24 -0500
                Re: Php login/registration page Jerry Stuckle <jstucklex@attglobal.net> - 2014-10-03 20:37 -0400
  Re: Php login/registration page Michael Vilain <vilain@NOspamcop.net> - 2014-09-30 18:38 -0700
  Re: Php login/registration page gordonb.opkrz@burditt.org (Gordon Burditt) - 2014-09-30 21:08 -0500

csiph-web