Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 13th, 2007, 02:43 PM
Registered User
 
Join Date: Mar 2007
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.
 
Old March 14th, 2007, 12:07 PM
Registered User
 
Join Date: Mar 2007
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.






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





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