wij zijn op school bezig om een inlogscript te schijven voor onze php webwinkel alleen werkt het script niet en komt hij met de fout:
"Fatal error: Can't use function return value in write context in: bla bla on line 42
wie o wie kan ons helpen???

<?php
error_reporting(E_ALL);
function controle($naam, $wachtwoord, $admin) {
?>
<?php
if ($admin == false) {
$sql = "SELECT Klant_ID, Username, Password FROM Klant WHERE Username='$naam'";
} else { // admin nodig? Haal eerste record op
$sql = "SELECT Klant_ID, Username, Password FROM Klant LIMIT 0,1";
}

$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
$password = mysql_result($result, 0, "Password");
$klantid = mysql_result($result, 0, "Klant_ID");
if ($wachtwoord != $password) {
return false;
} else {
return $klantid;
}
} else {
return false;
}

}

// Check naam en wachtwoord

if (isset($_POST['verzonden'])) {

$username = $_POST['username'];
$wachtwoord = md5($_POST['wachtwoord']);

$klantid = controle($username, $wachtwoord, $admin);

if ($klantid != false) {

$_SESSION['username'] = $username;
$_SESSION['wachtwoord'] = $wachtwoord;
$_SESSION['klantid'] = $klantid;

}

}

if (isset(controle($_SESSION['username'], $_SESSION['wachtwoord'], $admin) == false)) {

echo "<form method=\"post\" action=\"".$_SERVER{"PHP_SELF"]."?";
reset($_GET); // Zet de array pointer op 0, begin bij het begin
// Stuur meegestuurd variabelen opnieuw mee.
while($getvar = each($_GET)) {
$varnaam = $getvar['key'];
$varinhoud = $getvar['value'];
echo "$varnaam=$varinhoud&";
}
echo "\">\n";
echo "Naam: ";
echo "<input type=\"text\" name=\"username\">";
echo "<br>";
echo "Wachtwoord: ";
echo "<input type=\"password\" name=\"wachtwoord\">";
echo "<br>";
echo "<input type=\"submit\" value=\"verzenden\" name=\"verzonden\">";
echo "</form>";
echo "<p>Nog niet geregistreerd? <a href=\"aanmeldformulier.php\">[Registreer hier]

</a><br>";

if (isset)($admin == "true") {
echo "<p>--- Admin status is vereist!";
}
?>
Is het niet isset($admin) op regel 65?
het script op regel 65 is er voor dat het script kan zien of het gaat om een administrator of niet. en dat stukje werkt wel.
Je pas isset() niet op een juiste manier toe. Zo hoort bijvoorbeeld regel 42 er hoogstwaarschijnlijk zo uit te zien:
<?php
if (controle($_SESSION['username'], $_SESSION['wachtwoord'], $admin) == false)
?>
Op regels 65 is die isset inderdaad ook niet juist toegepast. Dat zou zoiets moeten zijn:
<?php
if(isset($admin) && $admin == true)
?>
ik heb alles toegepast maar nu krijg ik de volgende fouten:

Notice: Undefined variable: _SESSION in ... line 42

Notice: Undefined variable: _SESSION in ... line 42

Notice: Undefined variable: admin in ... on line 42


<?php
error_reporting(E_ALL);
function controle($naam, $wachtwoord, $admin) {
?>

<?php
if ($admin == false) {
$sql = "SELECT Klant_ID, Username, Password FROM Klant WHERE Username='$naam'";
} else { // admin nodig? Haal eerste record op
$sql = "SELECT Klant_ID, Username, Password FROM Klant LIMIT 0,1";
}

$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
$password = mysql_result($result, 0, "Password");
$klantid = mysql_result($result, 0, "Klant_ID");
if ($wachtwoord != $password) {
return false;
} else {
return $klantid;
}
} else {
return false;
}

}

// Check naam en wachtwoord

if (isset($_POST['verzonden'])) {

$username = $_POST['username'];
$wachtwoord = md5($_POST['wachtwoord']);

$klantid = controle($username, $wachtwoord, $admin);

if ($klantid != false) {

$_SESSION['username'] = $username;
$_SESSION['wachtwoord'] = $wachtwoord;
$_SESSION['klantid'] = $klantid;

}

}

if (controle($_SESSION['username'], $_SESSION['wachtwoord'], $admin) == false) {

echo "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."?";
reset($_GET); // Zet de array pointer op 0, begin bij het begin
// Stuur meegestuurd variabelen opnieuw mee.
while($getvar = each($_GET)) {
$varnaam = $getvar['key'];
$varinhoud = $getvar['value'];
echo "$varnaam=$varinhoud&";
}
echo "\">\n";
echo "Naam: ";
echo "<input type=\"text\" name=\"username\">";
echo "<br>";
echo "Wachtwoord: ";
echo "<input type=\"password\" name=\"wachtwoord\">";
echo "<br>";
echo "<input type=\"submit\" value=\"verzenden\" name=\"verzonden\">";
echo "</form>";
echo "<p>Nog niet geregistreerd? <a href=\"aanmeldformulier.php\">[Registreer hier]

</a><br>";

if(isset($admin) && $admin == true) {
echo "<p>--- Admin status is vereist!";
}
exit;
}
?>
Waar staat de functie session_start() ?
ik heb nu session start boven in het script gezet maar nu doet hij het nog niet

Notice: Undefined variable: _SESSION in authenticatie.php on line 49

Notice: Undefined variable: _SESSION in authenticatie.php on line 49

Notice: Undefined variable: admin in authenticatie.php on line 49

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at authenticatie.php:49) in authenticatie.php on line 8

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at authenticatie.php:49) in authenticatie.php on line 8
session_start() wel uitvoeren voordat je iets op het scherm zet.

output started at authenticatie.php:49


Op regel 49 komt iets op het scherm voordat je session_start() aanroept...
Ik heb de sessie nu gestart met een appart php bestand.

nu krijg ik nog de volgende meldingen vooral die admin weet ik niet

Notice: Undefined variable: admin in authenticatie.php on line 36

Notice: Undefined index: username in authenticatie.php on line 48

Notice: Undefined index: wachtwoord in authenticatie.php on line 48

Notice: Undefined variable: admin in authenticatie.php on line 48
Blijkbaar bestaat de variabele $admin niet. Zorg voordat je een variabele gebruikt altijd dat je controleert of de variabele wel bestaat:
<?php
if(isset($var))
{
// $var gebruiken
}
?>
het $admin staat in het script dat authenticatie.php aanroept. zo kan het script zien of het om een admin gaat of niet zo ja dat is de eerste rij in de tabel Klant de admin. in het php bestand winkel wagen staat dan <?php $admin = false; ?>
is dit wel goed dan ?

Reageren