561
بناء مشاريع PHP و MySQL عملية
الجزء V
// passwords not the same
if ($passwd != $passwd2)
do_html_heading("Problem:");
echo "The passwords you entered do not match
." and try again.";
do_html_footer();
exit;
}
please go back"
// check password length is ok
// ok if username truncates, but passwords will get
// munged if they are too long.
if (strlen($passwd) <6 || strlen($passwd) >16)
{
}
do_html_header("Problem:");
echo "Your password must be between 6 and 16 characters."
. "Please go back and try again.";
do_html_footer();
exit;
// attempt to register
$reg_result
register($username, $email, $passwd);
if ($reg_result == "true")
{
}
// register session variable
$valid_user
=
$username;
session_register("valid_user");
// provide link to members page
do_html_header("Registration successful");
echo "Your registration was successful. Go to the members page ."to start setting up your bookmarks!";
do_HTML_URL("member.php", "Go to members page");
else
{
// otherwise provide link back, tell them to try again do_html_header("Problem: ");
echo $reg_result;
do_html_footer();
exit;
24
?>
}
// end page
do_html_footer();
هذا هو
أول نص برمجي فيه أي تعقيد نظرنا إليه في هذا البرنامج.
يبدأ النص البرمجي بشمل ملفات دالات البرنامج ويبدأ جلسة (عندما يشترك المستخدم، سننشئ إسمه كمتغيّر جلسة كما فعلنا في الفصل 20).
ص ٥٤٥