Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
Password Reminder
Register
| 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 March 14th, 2009, 04:52 AM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Undefined session variables Ch.2 pg. 38-39

I have tried testing the php files below, and for some reason when i view the pages in my browser (firefox & IE have the same problem) i get the following error: Notice: Undefined variable: _SESSION in C:\wamp\www\moviesite\moviesite.php on line 20.

My cookies settings in Firefox & IE are to accept cookies from everyone, including 3rd parties and to keep them until they expire. I have used test scripts to check if sessions are working on my computer (the script is in the 3rd code block) and it shows that sessions are working (i double checked the tmp folder and a cookie has been created as well). I don't think there's anything wrong with the code, but possibly some sort of setting that will not allow session variables to be defined... i'm lost. I'm using WAMP with winXP and have php5.2.9 & apache2.2.11 installed. If anyone could help me figure out why this might be happening it would be a BIG help. Thanks.

Code:
<? php
 session_start();
 $_SESSION['username'] = 'Joe12345';
 $_SESSION['authuser'] = 1;
?>

<html>
 <head>
  <title>Find my Favorite Movie!</title>
 </head>
 
 <body>
  <?php
   $myfavmovie = urlencode('Life of Brian');
   echo "<a href=\"moviesite.php?favmovie=$myfavmovie\">";
   echo 'Click here to see information about my favorite movie!';
   echo '</a>';
  ?>
 </body>
</html>
Code:
<? php
 session_start();
 
 //check to see if user has logged in with a valid password
 if ($_SESSION['authuser'] != 1)
 {
  echo 'Sorry, but you don\'t have permission to view this page!';
  exit();
 }
?>

<html>
 <head>
  <title>My Movie Site - <?php echo $_GET['favmovie']; ?></title>
 </head>

 <body>
  <?php
   echo 'Welcome to our site, ';
   echo $_SESSION['username'];
   echo '! <br/>';
   echo 'My favorite movie is ';
   echo $_GET['favmovie'];
   echo '<br/>';
   $movierate = 5;
   echo ' My movie rating for this movie is: ';
   echo $movierate;
  ?>
 </body>
</html>
Code:
<?php
session_start();     // the FIRST THING YOU DO!

// to see sessions "not work", comment out the "session_start();" line

if (!isset($_SESSION['test'])) {
  echo "First activation: setting session variable";
  $_SESSION['test'] = 1;
} else
  echo "SESSIONS ARE WORKING! activation: ", (++$_SESSION['test']);
?>
Reply With Quote
  #2 (permalink)  
Old March 14th, 2009, 01:51 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

Unless it is just your code posting funnily, you will want to take out the spaces between the <? and php at the top of the files. Doing this on my machine (running php5) caused the whole php block to be ignored, and so the session_start(); is not run.
Saying that, I didn't get an undefined variable error, so there may be some other issue as well.
Reply With Quote
  #3 (permalink)  
Old March 14th, 2009, 02:19 PM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yeah, that seems to have been the problem... but it took me a long time to realize that i did that in BOTH files! after hours of confusion and posting in 2 forums, i can finally get back to learning PHP. thanks a lot philip_cole!
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
XSLTC compiler error about undefined variables cox1019823 XSLT 1 May 17th, 2006 08:50 AM
Ch 2 Page 53: Undefined index: authuser Airidh BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 25 February 22nd, 2005 07:34 PM
CH 5 pg 160 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 8 November 12th, 2003 11:23 PM
CH 3 pg 76 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 26th, 2003 08:46 PM
undefined variables skicrud Beginning PHP 1 September 8th, 2003 02:58 PM



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


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