 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
giwababatunde
Joined: 12 Mar 2008 Posts: 6
|
Posted: Sat Mar 29, 2008 6:44 am login code in php |
|
|
|
Hi everybody, can someone help me for login code in php ? for my user to login before they can have access.
i will be very greateful if my request will be favourable considered.
thanks. |
|
yangyang

Joined: 05 Oct 2006 Posts: 23 Location: kavoir.com
|
Posted: Sun Mar 30, 2008 7:38 pm |
|
|
|
For the simplest way, you'd have 2 files:
auth.php
| Code: |
<?php
function isLegalUser($un, $pwd) {
return ($un == 'adam' && $pwd == 'smith');
}
?>
|
any.php
| Code: |
<?php
session_start();
require_once('auth.php');
if (isset($_SESSION['un']) && isset($_SESSION['pwd'])) {
if (isLegalUser($_SESSION['un'], $_SESSION['pwd'])) {
echo 'session active';
// only display member only data here
} else {
echo 'bad session!';
}
} else {
if (!empty($_POST['un']) && !empty($_POST['pwd'])) {
if (isLegalUser($_POST['un'], $_POST['pwd'])) {
$_SESSION['un'] = $_POST['un'];
$_SESSION['pwd'] = $_POST['pwd'];
echo 'logged in';
}
} else {
?>
<p>Member only area, log in first.</p>
<form action='any.php' method='post'>
<input type='text' name='un' />
<input type='password' name='pwd' />
<input type='submit' value='Log in' />
</form>
<?php
}
}
?>
|
|
|
Daler
Joined: 23 May 2008 Posts: 31
|
Posted: Tue Aug 19, 2008 9:33 am |
|
|
|
| I wrote a very simple one of these. But, it's better for protecting areas like an Admin area, as you can only have one user. |
|
kiad_198
Joined: 12 Aug 2008 Posts: 4
|
Posted: Thu Aug 21, 2008 7:51 pm hi... |
|
|
|
try to watch this video ....
http://www.youtube.com/watch?v=7JmSf9JfQjY
it may help you.... |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
 |
|
|
|
|
|
|