Jump to content

Login form questions


MrCostari

Recommended Posts

Hello everybody,

I need to make a login form and I need to complete that this sunday.

I done pretty much most of it, except 1, pretty important thing.

That is letting the username stay in the form field when only the password field is wrong.

But for that, I need to stay on the same page and the problem is I need to use a switch, so that gets a little difficult for me.

I also MUST use template power, that's why I only show my PHP code.

I saw a video on YouTube, where they explained to use different files and link them to each other by using require and include.

They used a index.php file and a loginform.inc.php.

But since I'm using template power AND a switch, I don't think that will help me.

But he did used something like isset and also header function. And he managed to stay on the same page, by using index and loginform.inc.

Is there a way I can use that do? Or do I have to use something totally different?

Thanks much for any help :)

 

<?php
session_start();
$link = mysql_connect('localhost', 'root', '');
$db_selected = mysql_select_db('mydb', $link);

error_reporting(0);

include("includes/class.TemplatePower.inc.php");

$tpl = new TemplatePower("Werkbron4.html");
$tpl->prepare();

switch($_GET['actie'])
{	
case logout:

	if($_POST['submit'])
	// controleren of er op logout gedrukt is
	{		
		$_SESSION['accountsid'] = "";
		$_SESSION['groepenid'] = "";
		// de sessie leeghalen

		$tpl->newBlock("LOGOUT_SESSION");
		$tpl->assign("LOGOUT_SESSION", "U bent uitgelogd.");
		// tekst weergeven nadat er op logout gedrukt is
	}

	else
	{
			$tpl->newBlock("LOGOUT_FORM");
			// zo niet, terug naar formulier
	}
break;

case login_sql:

	if($_POST['gebruikersnaam'] AND $_POST['wachtwoord'])
	// controleren of er een gebruikersnaam en wachtwoord is ingevuld
	{		
		$gebruikersnaam = mysql_real_escape_string($_POST['gebruikersnaam']);
		$wachtwoord = mysql_real_escape_string($_POST['wachtwoord']);
		// zo ja, beveilig de gebruikersnaam en het wachtwoord tegen SQL injecties

		$check = mysql_query("SELECT * FROM accounts 
								WHERE gebruikersnaam='".$gebruikersnaam."'
								AND wachtwoord='".sha1($wachtwoord)."'");
								// haal de gegevens uit de database met deze query

		if(mysql_num_rows($check) == 1)
		// controleren of de gegevens over een komen. later bijwerken
		{
			$info = mysql_fetch_array($check);
			// ?? later bijwerken

			$_SESSION['accountsid'] = $info['accountsid'];
			$_SESSION['groepenid'] = $info['groepenid'];
			// gegevens in de sessie zetten

			$tpl->newBlock("LOGOUT_FORM");
			// laat de logout form zien

			$tpl->newBlock("TEXT_INLOG");
			$tpl->assign("TEXT_INLOG", "U bent ingelogd.");
			// deze tekst laten zien indien er succesvol ingelogd is

				if($_SESSION['groepenid'] == 1)
				// kijken of het groepenid van het account dat inlogt overeenkomt met het groepenid 1
				{
					$tpl->newBlock("LOGIN_KLANT");
					$tpl->assign("LOGIN_KLANT", "Welkom klant!");
					// zo ja, laat deze tekst zien en eventueel andere informatie die een klant mag zien/doen
				}

				elseif($_SESSION['groepenid'] == 2)
				// kijken of het groepenid van het account dat inlogt overeenkomt met het groepenid 2
				{
					$tpl->newBlock("LOGIN_ADMIN");
					$tpl->assign("LOGIN_ADMIN", "Welkom Admin!");	
					// zo ja, laat deze tekst zien en eventueel andere informatie die een admin mag zien/doen
				}

				else
				{
					$tpl->newBlock("ERROR_GEEN");
					$tpl->assign("ERROR_GEEN", "U heeft geen toestemming om hier te komen.");
					// deze tekst laten zien als een account inlogt met een ander groepenid dan 1 of 2
				}

		}

		else
		{
			$check2 = mysql_query("SELECT * FROM accounts 
								WHERE gebruikersnaam='".$gebruikersnaam."'");
			// controleren of de ingevulde gebruikersnaam overeenkomt met degene in de database

			if(mysql_num_rows($check2) == 1)
			{
				$tpl->newBlock("ERROR_PASS");
				$tpl->assign("ERROR_PASS", "U heeft een ongeldig wachtwoord ingevuld.");
				// deze tekst laten zien als de ingevulde gebruikersnaam correct is, maar het wachtwoord niet
			}

			else
			{
				$tpl->newBlock("ERROR_GEB");
				$tpl->assign("ERROR_GEB", "U heeft een ongeldige gebruikersnaam ingevuld.");
				// deze tekst laten zien als de ingevulde gebruikersnaam ongeldig is
			}					

		}
	}

break;

default:

	$tpl->newBlock("LOGIN_FORM");

}	
$tpl->printToScreen();	
?>

Link to comment
Share on other sites

Sorry, but I'm using PHP for 4 weeks now, so I don't know much.

Could you explain it?

I'm not getting any error, and I don't think I should be messing with the template power files.

 

I just realised some things are in Dutch, my apologies, I hope it's not much of a problem, since it are mostly comments and errors or other texts I get when I login.

And BTW:

Gebruikersnaam = username

Wachtwoord = password

Groepen = groups

Klant = costumer

 

Ask me for anything else!

Link to comment
Share on other sites

You have to edit the template if you want the username to remain in the box.

 

This is what you need to do:

1)  Somewhere in this code you gave is the case in which the password is wrong.  You should be able to find that, since it's the case you said you were working on.

2)  Inside of that case, you re-display the login form somehow.  Find that.

3)  $tpl->assign() is the method your code uses to assign PHP variable content to the template.  Use $tpl->assign() to assign the username to a variable for the template.

4)  Inside the template file is an <input /> tag that the user uses to input their username.  Find it. 

5)  Insert template code such that, if the variable for their username is set, the <input /> tag gets a "value" attribute which contains the variable you assigned to the template.

 

Without your template code or a working knowledge of Dutch that's all I can really give you.

Link to comment
Share on other sites

Thanks so much!

I like your way of helping people, just like my teachers!

Help them a bit, but let them do some research!

It happens often people from my class ask me to send them my work, but I don't to that, I tell them that they don't learn anything from that, but ofcourse they don't care. :(

W/e next year they will be gone! hehe :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.