Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 26th, 2009, 05:19 PM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Understanding code

Well,
I am very new to working with PHP. So new in fact, that i can not fig'r out how to add multi-users to the code on page 45. i have tried several different ways to alter the code, but so far, nada. ne1 willing to help me?
thank you,
bob
here is the code
Code:
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;

//Check username and password information
if (($_SESSION['username'] == 'bob') and
    ($_SESSION['userpass'] == 'xxxxxxxxxx' )) {
	$_SESSION['authuser'] = 1;
} else {
    echo 'Sorry, but you don\'t have permission to view this page!';
    exit();     
}
i want to add my brother jim to this password protected page.
Reply With Quote
  #2 (permalink)  
Old February 27th, 2009, 08:18 AM
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

Hi bcrossb,

There are of course a number of ways you can work this, but for simplicity, you simply need to add another if statement to check for jim's login details.
Think about the logic of the page as opposed to the code:
Code:
- If the username and password equal bob's details
  - Set as logged in
- Otherwise, deny access
We want to slot in a check for jim's details between checking bob and denying access:
Code:
- If the username and password equal bob's details
  - Set as logged in
- Otherwise, if the username and password equal jim's details
  - Set as logged in
- Otherwise, deny access
To do this we can use the "else-if" statement:
Code:
if (($_SESSION['username'] == 'bob') and
    ($_SESSION['userpass'] == 'xxxxxxxxxx' )) {
    $_SESSION['authuser'] = 1;
} else if (($_SESSION['username'] == 'jim') and
    ($_SESSION['userpass'] == 'yyyyyyyyyy' )) {
    $_SESSION['authuser'] = 1;
} else {
    echo 'Sorry, but you don\'t have permission to view this page!';
    exit();     
}
You can do this for any number of users. Just keep adding the else ifs....

Let me know if that doesn't make sense
Phil
Reply With Quote
  #3 (permalink)  
Old March 5th, 2009, 02:54 AM
Registered User
 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding user name and password

nice!!!
very logical and clean. makes sense after i study it. thank you for the insight.
bob
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not understanding namespaces skaue XSLT 4 January 31st, 2009 11:10 AM
Need help understanding DataRow asp_convert ADO.NET 3 March 13th, 2007 02:39 PM
Need help understanding databinding asp_convert ASP.NET 2.0 Basics 0 February 11th, 2007 07:17 PM
understanding Variable use imroostercogburn C++ Programming 7 July 28th, 2006 06:15 PM



All times are GMT -4. The time now is 04:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.