HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
login code in php
Post new topic   Reply to topic    HTML Help Forum Index -> PHP
View previous topic :: View next topic  
Author Message
giwababatunde



Joined: 12 Mar 2008
Posts: 6

PostPosted: Sat Mar 29, 2008 6:44 am     login code in php Reply with quote

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

PostPosted: Sun Mar 30, 2008 7:38 pm     Reply with quote

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: 52

PostPosted: Tue Aug 19, 2008 9:33 am     Reply with quote

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

PostPosted: Thu Aug 21, 2008 7:51 pm     hi... Reply with quote

try to watch this video ....

http://www.youtube.com/watch?v=7JmSf9JfQjY


it may help you....
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> PHP All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial