Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 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 March 13th, 2007, 02:43 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 2nd chapter session question

I am currently attempting to pull a value from a server variable across three pages, but I'm having a problem.

On my login page, I am using the following code:

<?php
session_unset();
?>

<html>
<head>
<title>Please log in.</title>
</head>
<body>
<form method="post" action="movie1.php">
   <p>Enter your username:
    <input type="text" name="user">
   </p>
   <p>Enter your password:
    <input type="password" name="pass">
   </p>
   <p>
    <input type="submit" name="Submit" value="Submit")
   </p>
</form>
</body>
</html>

On movie1.php, I am using the following code to check that the login information is correct:

<?php
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;

if (($_SESSION['username'] == 'Joe') and
   ($_SESSION['userpass'] == '12345')) {
   $_SESSION['authuser'] == 1;} else {
      echo "Sorry, but you don't have permission to view this page.";
      exit();
      }
?>

On this page, there is also a link to another page that also checks for a properly authenticated user with the previous credentials. The problem that I'm having is that when someone clicks on the link, they receive an error message telling them that they do not have permission to view the page.

Here is the code from the page at the end of the link:

<?php
session_start();

if ($_SESSION['authuser'] !=1) {
   echo "Sorry, but you don't have permission to view this page.";
   exit();
}
?>

I am thinking that this problem is related to a server configuration issue, but I can't seem to put my finger on it. I don't know why the information in the session variable will be held for only one page.
Reply With Quote
  #2 (permalink)  
Old March 14th, 2007, 12:07 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The answer to this is that I was using a comparison operator in my attempt to assign a value to 'authuser'. A lesson to play closer attention next time.

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
2nd Question... Wolven BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 4 April 21st, 2007 03:25 PM
Newbie question on the 2nd ed: Class inheritance elde BOOK: Professional C#, 2nd and 3rd Editions 0 December 9th, 2004 03:00 AM
simple session question cygnusx04 Classic ASP Basics 2 October 21st, 2004 08:50 AM



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


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