# Gepost op 23-08-2010 13:03
Bewerkt door sebastiaan op 07-09-2010 11:22
Bewerkt door sebastiaan op 07-09-2010 11:22
Allereerst: Dit is GEEN stand-alone systeem! Je hebt het login systeem van Vlerk nodig (PHP loginsysteem OOP). Dit is een aanpassing.
Stap een: de hoofd login klasse. Sla dit bestand op als register.class.php
Stap twee. Zoals je ziet heb ik een PHP klasse gebruikt om een form te genereren. Sla dit bestand op als formgenerator.class.php
Stap drie
Open config.php en voeg deze twee regels toe:
Stap vier
Open header.php en pas de init functie aan tot er dit staat (of kopieer en plak het)
En voila. Je bent klaar. Verder zijn er geen aanpassingen nodig!
Changelog
1.0 : eerste code
1.0.1 : Code wat verbeterd en wat fouten eruit gehaald.
Stap een: de hoofd login klasse. Sla dit bestand op als register.class.php
- <?php
- /*
- * This is a register class for the login system. This used to be a function in the
- * header.php file but I've decided to move it to it's own class.
- * @author Sebastiaan Franken
- * @version 1.0.1
- * @since 1.0
- */
- class register
- {
- /*
- * The constructor here checks if the form is posted and then run some checks on it.
- * If those checks pass the user is added to the database.
- * If those checks aren't passed the user isn't added.
- */
- public function __construct()
- {
- {
- /* Maken an error array to store errors in */
- /*
- * Remove all trailing spaces from the inputs.
- * @since 1.0.1
- */
- /*
- * Check all form fields if they're empty. If they are an error gets added
- * to the error array. I'm NOT going to write comment on every field below.
- */
- {
- }
- {
- }
- if($controle != $wachtwoord)
- {
- }
- {
- }
- /*
- * If there are errors in the array return them to the user and
- * give them the option to try again
- */
- {
- $output = '<p>Helaas is er '.$count.' niet ingevuld, die wel verplicht zijn.</p>';
- $output .= '<ul>';
- foreach($fouten as $fout)
- {
- $output .= '<li>'.$fout.'</li>';
- }
- $output .= '</ul>';
- }
- else
- {
- /* Secure the database input and insert into
- * the database.
- */
- $wachtwoord = (constant('login_password_m5') === true) ? mysql_real_escape_string(md5($_POST['wachtwoord'])) : mysql_real_escape_string($_POST['wachtwoord']);
- $rang = 'gebruiker';
- /* Run the query or die with the error that insues */
- mysql_query("INSERT INTO gebruikers(gebruikersnaam, wachtwoord, rang) VALUES('".$gebruikersnaam."', '".$wachtwoord."', '".$rang."')") or die(mysql_error());
- /* Give a sucess message */
- $output = '<p>De gebruiker is geregistreed.</p>';
- }
- }
- else
- {
- $output = new form($_SERVER['REQUEST_URI']);
- $output->addLabel('Gebruikersnaam')
- ->addInput('titel', 'text')
- ->addLabel('Wachtwoord')
- ->addInput('wachtwoord', 'password')
- ->addLabel('Controle wachtwoord')
- ->addInput('controle', 'password')
- ->addButton('registreer', 'registreer', 'submit')
- ->output();
- }
- return $output;
- }
- }
- ?>
Stap twee. Zoals je ziet heb ik een PHP klasse gebruikt om een form te genereren. Sla dit bestand op als formgenerator.class.php
- <?php
- /*
- * You can create HTML forms with this class
- * @version 1.0.1
- * @since 1.0
- */
- class form
- {
- /* The form method */
- public $method;
- /* The action */
- public $action;
- /* The form buffer */
- private $buffer;
- /*
- * The system constructor to add a method and action
- * and start the form code.
- */
- public function __construct($action, $method='post')
- {
- $this->action = $action;
- $this->method = $method;
- $this->buffer = '<form method="'.$this->method.'" action="'.$this->action.'">';
- return $this;
- }
- /*
- * With this function you can add a 'label'
- * @since 1.0
- * @return string, HTML
- */
- public function addLabel($text)
- {
- $this->buffer .= '<p>'.$text.'</p>';
- return $this;
- }
- /*
- * With this function you can add a input to
- * the form.
- * @since 1.0
- * @return string, HTML
- */
- public function addInput($name, $type, $value=null)
- {
- $this->buffer .= '<p><input type="'.$type.'" name="'.$name.'" value="'.$value.'" /></p>';
- return $this;
- }
- /*
- * With this function you can add a textarea to the form.
- * @since 1.0
- * @return string, HTML
- */
- public function addTextarea($name, $content=null, $rows=null, $cols=null)
- {
- $this->buffer .= '<p><textarea name="'.$name.'" cols="'.$cols.'" rows="'.$rows.'">'.$content.'</textarea></p>';
- return $this;
- }
- /*
- * With this function you can add a button to the form
- * @since 1.0
- * @return string, HTML
- */
- public function addButton($type, $text, $name)
- {
- $this->buffer .= '<p><input type="'.$type.'" name="'.$name.'" value="'.$text.'" /></p>';
- return $this;
- }
- /*
- * This function returns the form to the user
- * @since 1.0
- * @return string, HTML
- */
- public function output()
- {
- $this->buffer .= '</form>';
- return $this->buffer;
- }
- }
- ?>
Stap drie
Open config.php en voeg deze twee regels toe:
- include_once('formcreator.class.php');
- include_once('register.class.php');
Stap vier
Open header.php en pas de init functie aan tot er dit staat (of kopieer en plak het)
- public function init()
- {
- /*
- * Check if the function is called by a post and if the loginsession is false
- */
- if($_SERVER['REQUEST_METHOD'] == 'POST' && self::$loginsessie === false)
- {
- /*
- * If the action field is set run a check on it to see what it is
- */
- {
- switch($_POST['actie'])
- {
- case 'login' : $this->controleer_gegevens(); break;
- /*case 'registreer_gebruikers' : $this->registreer_gebruikers(); break;*/
- case 'registreer_gebruikers' :
- $register = new register();
- break;
- }
- }
- }
- }
En voila. Je bent klaar. Verder zijn er geen aanpassingen nodig!
Changelog
1.0 : eerste code
1.0.1 : Code wat verbeterd en wat fouten eruit gehaald.
Mijn software heeft geen bugs. Het ontwikkelt gewoon ongedocumenteerde functies.
![[[party]]](/projects/plugins/ubb/smileys/smiley_party.gif)