Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 24th, 2008, 12:25 PM
Authorized User
 
Join Date: May 2008
Location: Newcastle upon Tyne, , United Kingdom.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default $_SESSION error in login.php

Hello,

I'm using the 'Beginning PHP5,Apache,And MySQL Web development' and on pages 55-56, you develop a login page for you movies site, every time I try to login I get this error message. it's supposed to load another page up, but doesn't and loads this error message. The lines in the message refer to:
$_SESSION['username'] = $_POST['user']; // line 5
$_SESSION['userpass'] = $_POST['pass']; // line 6


Welcome to my movie review site!
Today is May 24, 2008

Notice: Undefined index: user in C:\wamp\www\PHP_files\movie1.php on line 5

Notice: Undefined index: pass in C:\wamp\www\PHP_files\movie1.php on line 6
Sorry, but you don't have permission to view this page, you loser!

Thanks for any help

Reply With Quote
  #2 (permalink)  
Old June 2nd, 2008, 03:43 PM
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

I haven't got the book, but I think I've found the source code you are using:
<?php
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;

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

When you run this page, PHP will look for POSTed (form textbox) values named user and pass. If you run it directly without going via login.php, these obviously will not exist, and so you will get the error above.
Also double check that your login.php has <form method="post"> as opposed to method="get" and that the names of the fields correspond to the ones you are using in movie1.php (user and pass).

As an aside, you can add a simple check to make sure the POST values are set before you use them:
<?php
session_start();

<?php
session_start();

if(isset($_POST['user'])) {
  // if the index 'user' is set (exists) in the $_POST array, then use it
  $_SESSION['username'] = $_POST['user'];
}
else {
  // was not set, so set to a empty value
  $_SESSION['username'] = '';
}

// do the same for password
if(isset($_POST['pass'])) {
  $_SESSION['userpass'] = $_POST['pass'];
}
else {
  $_SESSION['userpass'] = '';
}

$_SESSION['authuser'] = 0;

//Check username and password information as before ...

HTH
Phil
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
login php Case Problem saifi4u PHP How-To 3 March 7th, 2007 12:58 AM
$_Session cant pass Value kelz84 Beginning PHP 1 March 21st, 2006 09:25 AM
Difficulty with $_SESSION mall9@hotmail.com Beginning PHP 11 March 11th, 2006 05:41 PM
No login with auth_user.php stefanocinfo BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 September 10th, 2005 03:34 AM
$_SESSION vs. $_GLOBALS Moharo Pro PHP 2 August 18th, 2003 02:27 PM



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


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