try too add little bit of code too Joomla login


#1

Hi

I try too add a little bit of code to a joomla compont login.
my goal is to protect the user-registration with a password.
I stumbeld upon an error I can’t fix. I think it hase something to do with the GOTO, but Iam nog sure

Can someone help me?

Thx!

[php]

<?php /** * @package Joomla.Site * @subpackage com_users * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @since 1.6 */ defined('_JEXEC') or die; JHtml::_('behavior.keepalive'); JHtml::_('behavior.tooltip'); JHtml::_('behavior.formvalidation'); ?> <?php deel_1: echo "

Toegang tot gebruikersregistratie 1

\n"; echo "\n"; echo "

Referentie :

\n"; echo "

Code :

\n"; echo "\n"; echo "

"; if (isset($_POST['verzenden'])) { //we gaan eerst controleren of de persoon wel op de SUBMIT knop heeft gedrukt d.m.v. de functie isset() echo "

goed dus doorgaan met script

\n"; } else { echo "nog niet , dus terug "; goto deel_1; } $file="ditdus.txt"; $naam=$_POST["naam"]; $pas=$_POST["pas"]; if (isset($naam) && $naam != "" && $pas != "") { $pointer=fopen($file,"r+"); $paswoorden=fread($pointer,filesize($file)); $paswoorden=explode(",",$paswoorden); $tel=count($paswoorden); for ($i=0;$i<$tel;$i++) { $filenaam=$paswoorden[$i]; $filenaam=trim($filenaam); $i++; $filepass=$paswoorden[$i]; $filepass=trim($filepass); if (($filenaam == $naam) && ($filepass == $pas)) { echo "correct paswoord !
\n"; $wachtwoord="oke"; } } fclose($pointer); } if (isset($wachtwoord) && $wachtwoord == "oke") { } else { echo "U heeft geen toegang, klik hier voor meer informatie
\n"; exit () } ?> <?php echo "verwijzing9 !
\n"; ?>
<?php if ($this->params->get('show_page_heading')) : ?>

<?php echo $this->escape($this->params->get('page_heading')); ?>

<?php endif; ?>
<form id="member-registration" action="<?php echo JRoute::_('index.php?option=com_users&task=registration.register'); ?>" method="post" class="form-validate">
<?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?>
<?php $fields = $this->form->getFieldset($fieldset->name);?>
<?php if (count($fields)):?>
	<fieldset>
	<?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.?>
		<legend><?php echo JText::_($fieldset->label);?></legend>
	<?php endif;?>
		<dl>
	<?php foreach($fields as $field):// Iterate through the fields in the set and display them.?>
		<?php if ($field->hidden):// If the field is hidden, just display the input.?>
			<?php echo $field->input;?>
		<?php else:?>
			<dt>
			<?php echo $field->label; ?>
			<?php if (!$field->required && $field->type != 'Spacer'): ?>
				<span class="optional"><?php echo JText::_('COM_USERS_OPTIONAL');?></span>
			<?php endif; ?>
			</dt>
			<dd><?php echo $field->input;?></dd>
		<?php endif;?>
	<?php endforeach;?>
		</dl>
	</fieldset>
<?php endif;?>
<?php endforeach;?>
	<div>
		<button type="submit" class="validate"><?php echo JText::_('JREGISTER');?></button>
		<?php echo JText::_('COM_USERS_OR');?>
		<a href="<?php echo JRoute::_('');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
		<input type="hidden" name="option" value="com_users" />
		<input type="hidden" name="task" value="registration.register" />
		<?php echo JHtml::_('form.token');?>
	</div>
</form>

[/php]


#2

Well, first, NEVER use GOTO’s… They just cause problems…

You have PHP code that posts a form, then you test for ‘verzenden’. So, this code would post the form and then check for ‘verzenden’ and then post it again… All of the code you want to goto should be INSIDE the if clause…

So, the first part of the code you posted should be something like this:
[php]

<?php if (isset($_POST['verzenden'])) { //we gaan eerst controleren of de persoon wel op de SUBMIT knop heeft gedrukt d.m.v. de functie isset() echo "

goed dus doorgaan met script

\n"; } else { echo "nog niet , dus terug "; echo "

Toegang tot gebruikersregistratie 1

\n"; echo "\n"; echo "

Referentie :

\n"; echo "

Code :

\n"; echo "\n"; echo "

"; } [/php] But, I am not sure about the rest of the page. You have code AFTER this code, so I am not sure what you are attempting to do. But, hopefully that helps....

#3

hi thanks

I will try your idea!

What is the problem with GOTO’s? I loved them in the oldschool Qbasic.


#4

LOL… QuickBasic!, QBasic! VB-DOS! ETC! Oooooh, the memories… LOL…

I have a huge box of EVERY basic system every made… Crazy… Even have some MS-DOS Visual Basic systems on diskettes… Hmmm, what’s a diskette???

Well, in those days, goto’s were common and usually jumped to another flow-point in the program.
You would jump around all over the place and all was well. (Until you had to debug it and follow a 100 goto’s…)

But, nowadays all ( ALL ) programming is designed to be more “object” orientated. So, each module or section of your program can work by itself to handle it’s chores. One benefit of this is that the compiler or processor can throw these into different threads in the CPU and process them faster. Are you aware that the current Intel i7 has, like around 4.5 BILLION transistors on the cpu chip? They are basically the same as 64 cpu’s all running different threads. So, breaking up parts of your code is must faster.

So, back to goto’s… If a goto is encountered, the program has to start over from the top and search down to that label, then move that place in the code. Since PHP is not really a compiled, but interpreted code (basically a text file), this can slow down the program while re-parsing for a label. It is a hold-over and I suspect many reading this may disagree with me. If you look at a million pages of tutorials out there, goto’s are gone. Everything is now done inside of functions and classes.

One last note on your code. You call the GOTO from inside an if clause. So, the if is not closed very well. If the IF is inside a for loop or while loop then there would be loose-ends left behind which could cause stacking issues. I have never tried to mess up a program on purpose to try this, but, I am sure it would happen under certain settings. Also, there is a variable scoping issue. If you create a variable inside certain areas and then jump out of the area, does PHP understand that? Lot’s to think about with GOTO’s… Well, now that I have ranted for 5 minutes… Hope that helps a little to why I hate GOTO’s!
Good luck fixing your code…


#5

Hm I see your point. as you might have noticed writting codes has bin a while for me. thanks to you I am a littebit more uptodate.