Benim bir "Öğrenme PHP"-kitapta oldukça ilginç bir bölüm okuma ve değiştirmek ve neden basit bir belgeyi, "büyük" bir şey, korumak için (benim kişisel web sitesinde kullanmak isteyen bir örnek kod üzerinde geldi ayrıca) parolaları şifrelemek yok.
I've used the php-sample and I just can't make it work at all.
Here it is (dont get scared by the length, it's really simple):
<?php
if ($_POST['_submit_check']) {
if ($form_errors = validate_form()) {
show_form($form_errors);
} else {
process_form();
}
} else {
show_form();
}
function show_form($errors = '') {
echo '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '">';
if ($errors) {
echo '<br>'
echo implode('<br>', $errors);
echo '<br>';
}
echo 'Username: ';
echo '<input type="text" name="username" value="Username goes here">';
echo '<br>'
echo 'Password: ';
echo '<input type="password" name="password">';
echo '<br>'
echo '<input type="submit" name="submit" value="Log In">';
echo '<input type="hidden" name="_submit_check" value="1">'; //when the form is entered, this returns true and the first line of the document is good to go
echo '</form>';
}
function validate_form() {
$errors = array();
$users = array('admin' => 'pass123',
'notsoadmin' => 'pass1234');
if (!array_key_exists($_POST['username']) {
$errors[] = "Please enter username and password";
}
$saved_password = $users[ $_POST['password'] ];
if ($saved_password != $_POST['password']) {
echo "Password and username don't match. Please try again";
}
return $errors;
}
function process_form() {
$_SESSION['username'] = $_POST['username'];
echo "Welcome, $_SESSION[username]";
}
?>
Benim HTML ve malzeme önce ben de bu eklendi:
<?php session_start(); ?>
Açıkçası ben bir şey kaçırmış oldum ... Belki de ("hiçbir şey olmaz" dır) soruna neden olduğunu, $form_errors sağ başında bulunuyor, benim kitap oldu ama ben niçin / nerede emin değilim nereden geliyor?