OCC registration script

2006-05-13
2013-04-06
  • This is the script I wrote for version 1.2.6 and I use on my site: http://sandj.users.sonic.net/Games/occ/index.php

    <head>

    <?php
    include "accounts.php";

    function open_file($n)
    {
    $fd=fopen($n,"r") or die('...');
    $fs=fread($fd,filesize($n));
    fclose($fd);
    return $fs;
    }

    function save_file($m,$n,$o)
    {

        $n=trim($n);
        if($n=='')
        {
            $n=' ';
        }
        $n=str_replace("\n\n","\n",$n);
        $p=0;
        do
        {
            $fd=fopen($m,"w+") or die($o);
            $fout=fwrite($fd,$n);
            fclose($fd);
            $p++;
        }while(filesize($m)<5&&$p<5);

    }

    function AddUser($name, $password, $email)
    {
        $file = open_file("accounts.php");
        $search = "/* Add Users Here */";
        $file = preg_replace("$/\* Add Users Here \*/$", ", \&quot;$name\&quot; => \&quot;$password\&quot; $search ", $file);
        if ($email != '')
        {
            $search = "/* Add Emails Here */";
            $file = preg_replace("$/\* Add Emails Here \*/$", ", \&quot;$name\&quot; => \&quot;$email\&quot; $search ", $file);
        }
        save_file("accounts.php", $file, 0);
    }

    if(isset( $_POST ))
    {
    $new_name = $_POST["new_name"];
    $new_pass = $_POST["new_pass"];
    $new_email = $_POST["new_email"];
    if($new_name!='' && $new_pass!='')
    {
        $new_name = trim($new_name);
        $new_pass = trim($new_pass);
        $new_email = trim($new_email);
        /* First make sure the username is not already taken */
        /* If everything is ok, then add the user and redirect to index.php */
        if(!isset($passwords[$new_name]))
        {
            Adduser($new_name, $new_pass, $new_email);
            die("<title>Adding User</title><meta http-equiv=\&quot;Refresh\&quot; content=\&quot;2;url=index.php\&quot; /></head><body><div style=\&quot;color:black;background-color: white\&quot;>Adding User...</div></body></html>");
        }
        else
        {
            die("<title>Adding User</title><meta http-equiv=\&quot;Refresh\&quot; content=\&quot;30;url=index.php\&quot; /></head><body><div style=\&quot;color:black;background-color: white\&quot;>Adding User...<br /><bigger><bigger><b>Username is already taken!</b></bigger></bigger></div></body></html>");
        }
    }
    }
    ?>

    <title>Register</title>
      <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
    </head>
    <body>
    <h1>Online Chess Club Registration</h1>
    <form name="y" action="register.php" method="post">
    <table>
    <tr><td>Username</td><td><input type="text" size="30" name="new_name" /></td></tr>
    <tr><td>Password</td><td><input type="password" size="30" name="new_pass" /></td></tr>
    <tr><td>Email<small><em>(optional)</em></small></td><td><input type="text" size="50" name="new_email" /></td></tr>
    <tr><td> </td><td><input type="submit" name="submit" value="Register" /></td></tr>
    </table>
    <p><em>Please note that this regisration is only for access to the OCC games.  The forums require a seperate registration.  It is strongly suggested to fill out both forms, preferably with the same username.</em></p>
    </form>
    </body>
    </html>

     
  • The register.php works but the accounts.php don´t save the new user. (accounts.php=777)

    What can I do?