کد PHP:
<?php
session_start();
if(isset($_POST['username']) && isset($_POST['password']))
if(
($_POST['username'] == 'reza' && $_POST['password'] == 'test')
OR
($_POST['username'] == 'user2' && $_POST['password'] == 'pass2')
OR
($_POST['username'] == 'user3' && $_POST['password'] == 'pass3')
)
{
$_SESSION['username'] = 'reza';
HEADER('LOCATION: index.php');
}
else
die('wrong username/password!');
?>
يا اگه به شكل بهتر و با آرايه ها و با استفاده از اين آموزش بخوايم بنويسيم اينطوري ميشه:
http://www.webhostingtalk.ir/f148/آر...ر-php-13562/
کد PHP:
<?php
$users = array(
'user1'=>'pass1',
'user2'=>'pass2',
'user3'=>'pass3',
'user4'=>'pass4',
'user5'=>'pass5',
);
$login = false;
if(isset($users[$_POST['username']))
if($users[$_POST['username']] == $_POST['password'])
$login = true;
if($login)
{
$_SESSION['username'] = $_POST['username'];
HEADER('LOCATION: index.php');
}
else
die('wrong username/password!');
?>
البته اين روش ها در مقايسه با ديتابيس خيلي ضعيف تر هستند.