Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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
  #1 (permalink)  
Old April 27th, 2004, 10:49 PM
Authorized User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default CH:2 Passing Variables throught a URL.

I am having a little trouble with the codes in chapter 2 hope you can help me!
I am missing the varible "Stripes" on page 50. I am using register_globals OFF with $_REQUEST['varname']

here is the code from the book.

movesite.php file

<?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='http://localhost/wrox/moviesite.php?favmovie=$myfavmovie'>";
     echo "Click here to see information about my favorite movie!";
     echo "</a>";
?>
</BODY>
</HTML>


movie1.php file

<?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, you loser!";
     exit();
     }
?>
<HTML>
<HEAD>
<TITLE>My Movie Site - <?php echo $_REQUEST['favmovie'] ?></TITLE>
</HEAD>
<BODY>
<?php
     echo "Welcome to our site, ";
     echo $_SESSION['username'];
     echo "! <br>";
     echo "My favorite movie is ";
     echo $_REQUEST['favmovie'];
     echo "<br>";
     $movierate=5;
     echo "My movie rating for this movie is: ";
     echo $movierate;

?>
</BODY>
</HTML>


  #2 (permalink)  
Old April 28th, 2004, 01:13 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

This feels like a problem with the sessions not being saved, which has become a problem here lately. Rather than reiterate the problem here, read the replies to the following posts:

Ignore the original topic, just read my replies..
http://p2p.wrox.com/topic.asp?TOPIC_ID=12148
http://p2p.wrox.com/topic.asp?TOPIC_ID=12565

Follow the steps outlined for troubleshooting sessions, also, before you begin troubleshooting, make sure that you have error_reporting set to E_ALL and display_errors set to on in the php.ini file. On Windows look in C:\Windows\php.ini and open the file with a plain text editor, be sure to restart Apache after every modification to the file. The display_errors directive is set to off by default! So you could be missing out on important error output. Let me know if you're still not getting any results.


Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
  #3 (permalink)  
Old April 28th, 2004, 01:17 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Also, a more obvious solution to the problem is the session id isn't getting passed to the next script. This is done by cookies by default, but cookies have to be enabled in your browser and the session.use_cookies directive in php.ini must have a value of 1.

So, to make sure try this:
Code:
echo "<a href='http://localhost/wrox/moviesite.php?favmovie=$myfavmovie&sid=".session_id()."'>";
This will pass the session id via the GET method.

Without the session id PHP won't be able to associate session data with the same user between connections. This results in a new session being created on the second page and your session data being lost. In the modification there I've added a reference to the session id which can be called 'sid' or 'PHPSESSID', on the next page PHP will automatically pick up the session id and associate the data, thereby retreiving your variables (after a call to session_start() of course). Besides passing along the session id this way, you can just enable cookies in your browser and make sure the session.use_cookies directive has a value of 1 and all should be fine.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
  #4 (permalink)  
Old April 28th, 2004, 02:16 AM
Authorized User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the help but it was just a typo my bad :)
  #5 (permalink)  
Old April 28th, 2004, 02:30 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:Originally posted by GraphicArmy

 Thanks for you help but this in the basic code for my little missing problem
I'm not following you, do you still not have this working?

In your new post you are mispelling the 'favmovie' indice as 'favmovvie'.

echo $_REQUEST['favmovvie'];

Should be:

echo $_REQUEST['favmovie'];

Though this is referenced correctly in your previous post.



Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
  #6 (permalink)  
Old April 28th, 2004, 02:36 AM
Authorized User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks :)



Similar Threads
Thread Thread Starter Forum Replies Last Post
URL variables in XSL Pinguin89 XSLT 1 March 16th, 2006 10:57 AM
Ch. 2 - Passing Variables with Sessions tks001 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 February 20th, 2006 07:26 PM
Url Variables cbevey XSLT 5 December 21st, 2005 10:33 AM
CH. 4 Creating Local Variables mcauliff BOOK: Beginning ASP 3.0 1 March 3rd, 2005 03:57 PM
Sending URL with variables cckiat General .NET 4 December 7th, 2004 06:08 AM





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