Offered PHP MYSQL Registrion Example

JustinB
2007-07-30
2012-10-30
  • JustinB

    JustinB - 2007-07-30

    First off, if this isn't appropriate to put here, I apologize. I'm just trying to help the project.

    Below is an example script I use to register users to my murmur server.

    Please note that it requires the use of PHP & MySQL (not SQLite). If you want to feel free to modify, distribute, or even add to SVN. I used a Mangos Project registration page as a starting point. It uses the $create tag for the create button so it is suggested to create a button and it in the the image path listed, otherwise it won't look so good.

    BEGIN
    <?php
    /*
    Account Regsitration for Mumble v1.0 - 30.07.2007

        Partial content adopted from SPORA v1.2 Created by mirage666 (c) (mailto:mirage666@pisem.net icq# 152263154)
    
        Updated for Murmur running on MySQL by jbousquet.
    
        Tested against Murmur Version 1.0
    

    */

    $host="host"; // HOST for Mumble database
    $user="user" ; // USER for Mumble database
    $password="password"; // PASS for Mumble database
    $db="database"; // NAME of Mumble database
    $database_encoding='CP1251'; // Set encoding
    $img_base="img/"; // Image dir

    // Uncomment the line below (and on line 233) if you want to add the new player to the group listed. Be sure to already have the group created off the Root channel. Also, to have added permissions take effect, the murmur server must be restarted as of version 1.0.
    // $groupname='defaultgroup'; // GROUP to add new player into (OPTIONAL)

    $button="create.gif";
    $background='background.jpg';
    $text = Array(
    'acc' => 'Creation of account',
    'create' => 'is completed !',
    'failed' => 'was not possible !',
    'not_all' => 'Fields are not all filled',
    'on' => 'on',
    'off' => 'offline',
    'name' => 'Account Name',
    'password' => 'Password',);

    class DBLayer
    {
    var $link_id;
    var $query_result;
    var $saved_queries = array();
    var $num_queries = 0;

        function DBLayer($db_host, $db_username, $db_password, $db_name)
        {
                $this-&gt;link_id = @mysql_connect($db_host, $db_username, $db_password, true);
    
                if ($this-&gt;link_id)
                {
                        if (@mysql_select_db($db_name, $this-&gt;link_id))
                                return $this-&gt;link_id;
                        else
                                error('Unable to select database. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
                }
                else
                        error('Unable to connect to MySQL server. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
        }
    
        function query($sql)
        {
                $this-&gt;query_result = @mysql_query($sql, $this-&gt;link_id);
    
                if ($this-&gt;query_result)
                {
                        ++$this-&gt;num_queries;
                        return $this-&gt;query_result;
                }
                else
                {
                        return false;
                }
        }
    
        function result($query_id = 0, $row = 0)
        {
                return ($query_id) ? @mysql_result($query_id, $row) : false;
        }
    
        function fetch_assoc($query_id = 0)
        {
                return ($query_id) ? @mysql_fetch_assoc($query_id) : false;
        }
    
        function fetch_row($query_id = 0)
        {
                return ($query_id) ? @mysql_fetch_row($query_id) : false;
        }
    
        function num_rows($query_id = 0)
        {
                return ($query_id) ? @mysql_num_rows($query_id) : false;
        }
    
        function affected_rows()
        {
                return ($this-&gt;link_id) ? @mysql_affected_rows($this-&gt;link_id) : false;
        }
    
        function insert_id()
        {
                return ($this-&gt;link_id) ? @mysql_insert_id($this-&gt;link_id) : false;
        }
    
        function get_num_queries()
        {
                return $this-&gt;num_queries;
        }
    
        function get_saved_queries()
        {
                return $this-&gt;saved_queries;
        }
    
        function free_result($query_id = false)
        {
                return ($query_id) ? @mysql_free_result($query_id) : false;
        }
    
        function escape($str)
        {
                if (function_exists('mysql_real_escape_string'))
                        return mysql_real_escape_string($str, $this-&gt;link_id);
                else
                        return mysql_escape_string($str);
        }
    
        function error()
        {
                $result['error_sql'] = @current(@end($this-&gt;saved_queries));
                $result['error_no'] = @mysql_errno($this-&gt;link_id);
                $result['error_msg'] = @mysql_error($this-&gt;link_id);
    
                return $result;
        }
    
        function close()
        {
                if ($this-&gt;link_id)
                {
                        if ($this-&gt;query_result)
                                @mysql_free_result($this-&gt;query_result);
    
                        return @mysql_close($this-&gt;link_id);
                }
                else
                        return false;
        }
    

    }

    function error($message, $file, $line, $db_error = false)
    {
    global $siteerrors;
    $s = "\t\t".'Error: <strong>'.$message.'.</strong>'."\n";
    echo $s;
    }

    if (empty($_POST['username']) and empty($_POST['passw']) and empty($_POST['email']))
    {
    $cont=' <TR>
    <TD rowSpan=6></TD>
    <TD vAlign=center align=left width=190><B
    style="FONT-SIZE: 8pt; COLOR: white; LETTER-SPACING: 3px; FONT-VARIANT: small-caps"><LABEL
    for=username>'.$text["name"].':</LABEL>&nbsp;</B><BR><INPUT
    id=username style="WIDTH: 175px" tabIndex=1 maxLength=16
    size=18 name=username></TD>
    <TD rowSpan=6></TD></TR>
    <TR><TD width=190 height=1></TD></TR>
    <TR><TD width=190 height=1></TD></TR>
    <TR>
    <TD vAlign=center align=left width=190><B
    style="FONT-SIZE: 8pt; COLOR: white; LETTER-SPACING: 3px; FONT-VARIANT: small-caps"><LABEL
    for=passw>'.$text["password"].':</LABEL>&nbsp;</B><BR><INPUT id=passw
    style="WIDTH: 175px" tabIndex=2 type=password maxLength=16
    size=18 name=passw></TD></TR>
    <TR>
    <TD vAlign=center align=left width=190><B
    style="FONT-SIZE: 8pt; COLOR: white; LETTER-SPACING: 3px; FONT-VARIANT: small-caps"><LABEL
    for=email>E-mail:</LABEL>&nbsp;</B><BR><INPUT id=email
    style="WIDTH: 175px" tabIndex=2 maxLength=50
    size=18 name=email></TD></TR>
    <TR>
    <TD align=left>
    <TABLE cellSpacing=0 cellPadding=0 border=0>
    <TBODY>
    <TR>
    <TD></TD>
    <TD></TD>
    <TD></TD></TR></TBODY></TABLE></TD></TR>
    <TR>
    <TD align=left colSpan=3>
    <TABLE cellSpacing=0 cellPadding=0 border=0>
    <TBODY>
    <TR>
    <TD></TD>
    <TD><INPUT class=button
    style="WIDTH: 168px; HEIGHT: 39px" tabIndex=3 type=image
    alt=Create src="'.$img_base.$button.'"
    value=Create border=0></TD>
    </TR></TBODY></TABLE></TD></TR>';
    }
    elseif (empty($_POST['username']) or empty($_POST['passw']) or empty($_POST['email']))
    {

        $cont='&lt;TR&gt;&lt;TD rowSpan=6&gt;&lt;TD align=Center&gt;&lt;SMALL class=error&gt;
    

    '.$text["not_all"].'
    <br><br><a href="" onClick="history.go(-1)">Back</a></SMALL></TD></TD></TR>';

        }
        else
        {
        $username = htmlspecialchars(trim(&quot;$_POST[username]&quot;));
        $passw = trim($_POST['passw']);
        $email = htmlspecialchars(trim($_POST['email']));
        $ip = getenv('REMOTE_ADDR');
        $mumble_db = new DBLayer($host, $user, $password, $db);
        $mumble_db-&gt;query(&quot;SET NAMES $database_encoding&quot;);
    

    $ip_cr=0;
    $title=('');

        if($mumble_db-&gt;query(&quot;INSERT INTO `players` (`name`,`email`,`pw`) VALUES ('$username','$email','$passw')&quot;))
                {
    

    // IF you want to add your player to a group automatically uncomment the line below.
    // $mumble_db->query("INSERT INTO group_members (group_id,player_id,addit) VALUES ((SELECT groups.group_id FROM groups WHERE groups.name='$groupname' AND groups.channel_id='0'),(SELECT players.player_id FROM players WHERE players.name='$username'),'1')");
    $cont='<TR><TD rowSpan=6><TD align=Center><SMALL>
    '.$text["acc"].'<br><strong>'.$username.'</strong><br>'.$text["create"] .'
    </SMALL></TD></TD></TR>';
    }
    else
    {
    $cont='<TR><TD rowSpan=6><TD align=Center><SMALL class=error>
    '.$text["acc"].'<br><strong>'.$username.'</strong><br>'.$text["failed"].'
    <br><br><a href="" onClick="history.go(-1)">Back</a></SMALL></TD></TD></TR>';
    }
    $mumble_db->close();
    unset($mumble_db);
    }
    // Main part !!!
    ?>
    <HTML><HEAD><META HTTP-EQUIV="Pragma" CONTENT="no-cache"><TITLE>Create an account on out Mumble server</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=windows-1251"><LINK id=bnetstyle href="<?php print $img_base ?>style.css" type=text/css rel=stylesheet>
    <SCRIPT language=javascript>
    <!--
    var styleSheet;
    var agt = navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();
    var verInt = parseInt(appVer);
    var ie = (appVer.indexOf('msie') != -1);
    var opera = (agt.indexOf('opera') != -1);
    var mozilla = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('opera')==-1)
    && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)
    && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var ns4 = (mozilla && (verInt == 4));

    if (ie &amp;&amp; !opera) {
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;input&quot;, &quot;background-color: #040D1A&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;input&quot;, &quot;border-style: solid&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;input&quot;, &quot;border-width: 1px&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;input&quot;, &quot;border-color: #7F7F7F&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;input&quot;, &quot;color: #FFAC04&quot;);
    
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;background-color: #040D1A&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;border-style: solid&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;border-width: 1px&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;border-color: #7F7F7F&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;color: #FFAC04&quot;);
    
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;scrollbar-Base-Color: #012158&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;scrollbar-Arrow-Color: #7F7F7F&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;scrollbar-3dLight-Color: #7F7F7F&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;scrollbar-DarkShadow-Color: black&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;scrollbar-Highlight-Color: black&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;textarea&quot;, &quot;scrollbar-Shadow-Color: #00B3FF&quot;);
    
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;select&quot;, &quot;background-color: #040D1A&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;select&quot;, &quot;color: #FFAC04&quot;);
    
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;select.gray&quot;, &quot;background-color: #040D1A&quot;);
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;select.gray&quot;, &quot;color: #FFAC04&quot;);
    
      document.styleSheets[&quot;bnetstyle&quot;].addRule (&quot;ul.thread&quot;, &quot;margin-left: 22px;&quot;);
    }
    

    //-->
    </SCRIPT>
    </HEAD>
    <BODY text=#cccc99 vLink=#aaaaaa link=#ffffbb bgColor=#000000 leftMargin=0
    topMargin=0 marginheight="0" marginwidth="0">
    <FORM name=login_form method=post>
    <TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TBODY>
    <TR>
    <TD align=middle>
    <TABLE cellSpacing=0 cellPadding=0 background="
    <?php print $img_base ?><?php print $background ?>" border=0 style="background-repeat: no-repeat;">
    <TBODY>
    <TR>
    <TD vAlign=top>
    <DIV style="POSITION: relative">
    <DIV
    style="LEFT: 130px; WIDTH: 400px; POSITION: absolute; TOP: 0px"></DIV></DIV></TD>
    <TD></TD>
    <TD></TD></TR>
    <TR>
    <TD></TD>
    <TD>
    <TABLE cellSpacing=0 cellPadding=0 width=220 border=0>
    <TBODY>
    <?php print $cont ?></TBODY></TABLE></TD>
    <TD></TD></TR>
    <TR>
    <TD colSpan=3>
    <TABLE cellSpacing=0 cellPadding=0 border=0>
    <TBODY>
    <TR>
    <TD colSpan=3></TD></TR>
    <TR>
    <TD width=106></TD>
    <TD width=410><SMALL>

    <br><strong class=title><center><?php print $title ?></center></strong><br>
    <table cellpadding='3' cellspacing='0' align='center'>
    <tbody>
    <tr class=title>
    <td align='left' nowrap='nowrap' width=50></td>
    <td align='left' nowrap='nowrap' width=60><a href="<?php print $link.'0">'.$text['char'][0] ?></a></td>
    <td align='center' nowrap='nowrap' width=40><a href="<?php print $link.'1">'.$text['char'][1] ?></a></td>
    <td align='center' nowrap='nowrap' width=40><a href="<?php print $link.'2">'.$text['char'][2] ?></a></td>
    <td align='center' nowrap='nowrap' width=40><a href="<?php print $link.'3">'.$text['char'][3] ?></a></td>
    <td align='left' nowrap='nowrap' width=100><a href="<?php print $link.'4">'.$text['char'][4] ?></a></td>
    </tr>
    <tr><td class='txt' align='center' colspan='6' nowrap='nowrap'></td></tr>
    </tbody>
    </table>

                  &lt;/SMALL&gt;&lt;/TD&gt;
                &lt;TD width=124&gt;&lt;/TD&gt;&lt;/TR&gt;
              &lt;TR&gt;
                &lt;TD colSpan=3&gt;&lt;/TD&gt;&lt;/TR&gt;
                &lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/FORM&gt;&lt;/BODY&gt;&lt;/HTML&gt;
    

    EOF

     
    • Thorvald Natvig

      Thorvald Natvig - 2007-07-31

      What is the license on the original on which this is based?
      Also, it seems this does not do the extra step of verifying the email address. Could you add this?

       
    • Master Goodheart

      Looks great! I've already modified the perl script to use MySQL, but PHP would be better. As said it'd be nice to have email verification though.