p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > PHP/MySQL > PHP How-To
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 12th, 2009, 08:21 AM
Registered User
Points: 50, Level: 1
Points: 50, Level: 1 Points: 50, Level: 1 Points: 50, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Password navigation

The following code is part of a form/handler that directs a valid password entered to a valid page or a invalid password to a invalid page. A cookie javascript is also included.

My first ideal was to see if I could php include the $urlList to an external file that saves users passwords. Part of a different registration script.

Code:
<?php

# Set up the password strings and associated URLs. Note that all the elements of 
# this hash list but the last MUST be separated by commas. You may have as many
# password => URL combinations as you wish.
$urlList = array ('xyzzy'  => 'valid.html',
                  'abcdef' => 'valid.html',
                  '123456' => 'valid.html'
           );

# Set up the invalid password URL - this should also be set up in the JavaScript  
$invalidURL = 'invalid.html';

# The cookie name - this should be the same as in the JavaScript
$cookieName = 'validpassword';

# ******************************************************************************

# If there is nothing in the form's submit field, this is the first time in. 
# Simply display the form and await the user's input. Othwerwise, pick up the 
# password from the form.

if (isset ($_POST['submit']) && strlen($_POST['password']) > 0) {
  
  # See if the password provided by the user exists in the list.
  if (array_key_exists ($_POST['password'], $urlList)) {

    # Password found - first set the cookie 
    setcookie ($cookieName, 0, NULL,'/');
    
    # Now go to the page associated with the password.
    header ("Location: " . $urlList[$_POST['password']]);
  }
  else {

    # Password not found - go to the 'invalid password' page
    header ("Location: " . $invalidURL);
  }
}
?>
Sadly, the following highlighted mod is not allowing the content of the external flat file to behave as a $urlList. But jumps to the $invalidURL page.

I have copied the following code into the passwords.php file

Code:
$urlList = array ('xyzzy'  => 'valid.html',
                  'abcdef' => 'valid.html',
                  '123456' => 'valid.html'
           );
And modified the include call highlighted

Code:
<?php
$urlList = array(
'include'=> array(
'base' => './passwords.php'
    )
);
$invalidURL = 'invalid.html';

$cookieName = 'validpassword';

if (isset ($_POST['submit']) && strlen($_POST['password']) > 0) {
  
  # See if the password provided by the user exists in the list.
  if (array_key_exists ($_POST['password'], $urlList)) {

    # Password found - first set the cookie 
    setcookie ($cookieName, 0, NULL,'/');
    
    # Now go to the page associated with the password.
    header ("Location: " . $urlList[$_POST['password']]);
  }
  else {

    # Password not found - go to the 'invalid password' page
    header ("Location: " . $invalidURL);
  }
}
?>
<html>
<body>
<form id="myform" action="password.php" method="post">
<p>Try it: (passwords are <span style="color: #ff0000;">xyzzy, abcdef, 123456):</span> 
<span style="color: #ff0000; margin-left: 20px;">Enter password: 
<input type="password" name="password" maxlength="12" size="12" style="margin-left: 10px;" />
<input type="submit" name="submit" value="submit" style="margin-left: 30px; color: #f00;" />
</span></p>
</form>
</body>
</html>
This is getting a bit complicated and wonder if there is a simpler option that can be used
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Password site navigation phpnukes Beginning PHP 0 January 6th, 2009 09:03 PM
Navigation sg48 ASP.NET 2.0 Basics 2 February 13th, 2008 12:18 PM
Navigation volsha Dreamweaver (all versions) 1 July 20th, 2007 04:19 PM
navigation nidheeshkayal ASP.NET 2.0 Basics 0 March 16th, 2006 07:05 AM
Navigation JonnyRPI HTML Code Clinic 1 July 6th, 2003 06:33 AM



All times are GMT -4. The time now is 07:10 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc