PDA

Volledige versie bekijken : user login werkt niet


naate
%Europe/Berlin %439 %2007, 11:32
Hallo,

Ik volg het boek 'Phpvoor Flash, voor en door onterpers'. Maar nu ben ik dus bezig met het maken van een user login, uit hoofdstuk 2. Alleen steeds als er ingelogd wordt met de goede naam en het bijbehorende wachtwoord, kom je bij de tekst: 'Whoops, You need to supply a username and password'. Dus toen heb ik de kant-en-klare versie gedownload op www.friendsofed.com
Maar die doet precies hetzelfde!
Ik heb die gedownloade versie even op internet gezet: www.lavogue.nl/flash/login.html

Dit PHP script hoort erbij:

<?

// Create and fill username and password arrays.
// We also want to return a custom message for each user so
// we'll fill another array with those messaged
$usernames[] = "Steve";
$passwords[] = "nottelling";
$messages[] = "Welcome, oh masterful one!\nHow are you today?";

$usernames[] = "Matt";
$passwords[] = "itsasecret";
$messages[] = "Hello Sir Matt, knight of the purple jelly table! Did you bring my rubber wallpaper?";

$usernames[] = "Alan";
$passwords[] = "nmof2";
$messages[] = "Ah, hello Alan.\nYou'll be glad to know Chapter 2 is *nearly* finished!";


// Check that a username and password have been passed...
if (!isset($username) || empty($username) || !isset($password) || empty($password)) {

// If not tell Flash movie that we've failed and return error message
print "&result=Fail&errorMsg=" . urlencode("You need to supply a username and password");
exit;
}

// Set a variable so we can indicate whether a match was found or not
$matchFound = false;

// Now we loop through each entry in our arrays looking for a valid match
for ($count = 0; $count < count($usernames) && $matchFound == false; $count++) {

// If username and password matches entry...
if ($username == $usernames[$count] && $password == $passwords[$count]) {

// Get the user's message and indicate we've found a match
$message = $messages[$count];
$matchFound = true;
}
}

// If we found a match...
if ($matchFound) {

// Tell the Flash movie that login was successful and return custom message
print "&result=Okay&message=" . urlencode($message);
} else {

// Otherwise, tell Flash movie we failed
print "&result=Fail&errorMsg=" . urlencode("No match found for username/password");
}

?>

GBest
%Europe/Berlin %508 %2007, 13:12
je zou voordat je de loop begint even kunnen kijken hoe de array gevuld is door middel van print_r http://www.php.net/manual/en/function.print-r.php

print_r($array);



Verder zou ik deze regel:

if (!isset($username) || empty($username) || !isset($password) || empty($password)) {


vervangen door


$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
if (!isset($username) || empty($username) || !isset($password) || empty($password))
{


waarbij $_REQUEST wordt uitgelegd alhier: http://www.php.net/manual/en/reserved.variables.php

Want hoe stuur je de variabelen vanuit flash naar php atm?

mech7
%Europe/Berlin %520 %2007, 13:29
Het lijkt erop alsof het erg slecht (oud) is geschreven om te werken met register globals :s

GBest
%Europe/Berlin %523 %2007, 13:34
Ik begrijp je niet, wat is er mis met register globals? Is dat oud? nee toch? Je brengt me aan het twijfelen. Ik neem aan dat de php pagina als volgt wordt aangeroepen: "depagina.php?username=Abra&password=kadabra" . Dan is $_REQUEST gebruiken toch prima?

mech7
%Europe/Berlin %577 %2007, 14:50
Ik begrijp je niet, wat is er mis met register globals? Is dat oud? nee toch? Je brengt me aan het twijfelen. Ik neem aan dat de php pagina als volgt wordt aangeroepen: "depagina.php?username=Abra&password=kadabra" . Dan is $_REQUEST gebruiken toch prima?

Ja maar met register globals maakt hij daar automatisch variabelen van, dus niet superglobals als $_POST / $_GET / $_SERVER / $_REQUEST etc.. register globals staat tegenwoordig standaard ook uit omdat het leidt tot sneller onveilige scripts ;)