Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old November 24th, 2006, 04:03 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Interpreting "Running Membership with Sessions"

Hello there. I was reading through Hermawan's "Using Sessions in PHP" tutorial with interest in creating a somewhat secure authentication system for an admin control panel I'll be writing for a site. However, being a relative noob to php and mysql, I find it hard to understand what parts of the code mean. So I was wondering if someone could help me by explaining important parts and possibly giving me examples of sql queries that are needed to complete the code. Thanks.

Here's the code Hermawan provides:
php Code:
Original - php Code
  1. <?php
  2. // functions.php
  3.  
  4. function secure () {
  5.   if (!($_SESSION["member_id"]) || ($_SESSION["member_id"] == "")) {
  6.     Header("Location: ./login.php");
  7.     exit();
  8.   }
  9. }
  10. function login_check ($forms) {
  11.   $error = "";
  12.   $username = $forms["username"];
  13.   $password = $forms["password"];
  14.   if (trim($username) == "") $error .= "<li>Your username is empty.</li>";
  15.   if (trim($password) == "") $error .= "<li>Your password is empty.</li>";
  16.   /* from here, do your sql query to query the database to search for existing record with correct username and password */
  17.   if (trim($error)!="") return $error;
  18. }
  19.  
  20. function login ($forms) {
  21.   $username = $forms["username"];
  22.   $password = $forms["password"];
  23.   /* do your sql query again, but now returning the id of member */
  24.   return $member_id;
  25. }
  26. ?> 


php Code:
Original - php Code
  1. <?php
  2. // login.php
  3. include ("functions.php");
  4. if ($_POST) {
  5.   $error = login_check($_POST);
  6.   if (trim($error)=="") {
  7.     $_SESSION["member_id"] = login($_POST);
  8.     Header("Location: ./index.php") // Redirect correct member
  9.     exit();
  10.   } else {
  11.     print "Error:$error";
  12.   }
  13. }
  14. ?>
  15. <form method="post">
  16. Username : <input type="text" name="username"><br />
  17. Password : <input type="password" name="password"><br />
  18. <input type="submit" value="Login">
  19. </form>


php Code:
Original - php Code
  1. <?php
  2.   // index.php
  3.   include("functions.php");
  4.   secure();
  5. ?> 

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Interpreting "Running Membership with Sessions"


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway