Wrox Programmer Forums
|
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
 
Old July 26th, 2004, 04:26 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Chudz
Default Chapter 2 - Page 52, 53

 I am stuck on the session part of chapter 2. I done everything that the books has told me to and i have checked my code over and over again i don't have any errors! can someone help please?

This is what my browser shows when i load movie1.php:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\test\movie1.php:2) in C:\Program Files\Apache Group\Apache2\test\movie1.php on line 3

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\test\movie1.php:2) in C:\Program Files\Apache Group\Apache2\test\movie1.php on line 3
Click here to see information about my favourite movie

This is what shows when i load moviesite.php:

Parse error: parse error, unexpected '{' in C:\Program Files\Apache Group\Apache2\test\moviesite.php on line 5

http://www.uggle.com
http://www.leap2.co.uk
[email protected]
[email protected]
 
Old July 26th, 2004, 05:17 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

A parse error indicates a typo in the code. Look around line five for a typo. The other errors will likely go away once you correct the parse error. You can also post a snip of your code here and someone on the list will tell you what's wrong with it.

HTH!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old July 26th, 2004, 06:16 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Chudz
Default

ok this is my movie1.php file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?
    session_start();
    $_SESSION['username']="joe12345";
    $_SESSION['authuser']=1;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?
    $myfavmovie=urlencode("The Life of Brian");
    echo "<a href='http://localhost/moviesite.php?favmovie=$myfavmovie'>";
    echo "Click here to see information about my favourite movie";
    echo "</a>";

?>
</body>
</html>

and this is my moviesite.php file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?
    session_start();
//check to see if user has logged in with a valid password
    if ($_SESSION['authuser']!=1 {
    echo "Sorry you cant enter the site";
    exit();
    }
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>My movie site - <? $_REQUEST['favmovie'] ?></title>
</head>

<body>
<?
    echo "My favourite movie is" ;
    echo $_REQUEST['favmovie'];
    echo "<br>";
    $movierate=5;
    echo "My movie rating for this this movie is: ";
    echo $movierate;
?>
</body>
</html>

I am also use Dreamweaver to do these php files and im using FireFox explorer!

http://www.uggle.com
http://www.leap2.co.uk
[email protected]
[email protected]
 
Old July 26th, 2004, 06:23 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

You can't have any output before the call to session_start(). session_start() outputs a cookie in the HTTP headers, since you have the DOCTYPE included before the call to session_start() which is what's causing the errors.

Move the DOCTYPE so that it appears after the call to session_start().
Code:
<?
    session_start();
    $_SESSION['username']="joe12345";
    $_SESSION['authuser']=1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Also make sure that you don't have any whitespace, linebreaks before the opening <?php delimiter.

HTH!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old July 26th, 2004, 07:00 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Chudz
Default

ok thank you :D its all sorted now

http://www.uggle.com
http://www.leap2.co.uk
[email protected]
[email protected]
 
Old July 26th, 2004, 07:53 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Chudz
Default

oh no i have another problem :( can you help me again please!

I am doing the part where you make a cookie which remembers the log on details here is what error i get:

Warning: setcookie() expects parameter 3 to be long, string given in C:\Program Files\Apache Group\Apache2\test\movie1.php on line 2

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\test\movie1.php:2) in C:\Program Files\Apache Group\Apache2\test\movie1.php on line 3

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at C:\Program Files\Apache Group\Apache2\test\movie1.php:2) in C:\Program Files\Apache Group\Apache2\test\movie1.php on line 3

and here is the code for the php file:

<?
    setcookie('username', 'joe', 'time()+60');
    session_start();
    $_SESSION['authuser']=1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<?
    $myfavmovie=urlencode("The Life of Brian");
    echo "<a href='http://localhost/moviesite.php?favmovie=$myfavmovie'>";
    echo "Click here to see information about my favourite movie";
    echo "</a>";

?>
</body>
</html>

http://www.uggle.com
http://www.leap2.co.uk
[email protected]
[email protected]
 
Old July 26th, 2004, 08:03 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

time() is a function, so you can include that as part of the string. And +60 is an expression so that can't be part of the string either or it wouldn't get evaluated. ;)


setcookie('username', 'joe', time()+60);

That ought to do it.

HTH!

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old July 26th, 2004, 08:07 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Chudz
Default

oh i understand thanks :D

http://www.uggle.com
http://www.leap2.co.uk
[email protected]
[email protected]
 
Old February 19th, 2006, 07:09 PM
Registered User
 
Join Date: Feb 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am having a similar problem with the first example of setting a cookie. Any help is appreciated!

Here is the error on when loading movie1.php

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\test\movie1.php:1) in C:\Program Files\Apache Group\Apache2\test\movie1.php on line 2
Click here to see information about my favorite movie!

My code for movie1.php is (no leading spaces, etc.):

<?php
setcookie('username', 'Joe', time()+60);
session_start();
$_SESSION['authuser'] = 1;
?>

<html>

<head>

<title>Find my Favorite Movie!</title>

</head>

<body>

    <?php

      //adding this line

      $myfavmovie = urlencode("Life of Brian");

      //changed this line

      echo "<a href='moviesite.php?favmovie=$myfavmovie'>";

      echo "Click here to see information about my favorite movie!";

      echo "</a>";

    ?>

</body>

</html>

In php 5.1.2 - I have php.ini options set to(Passing variables w/sessions successful):

session.auto_start = 1
session.cookie_path = /
; Whether to use cookies.
session.use_cookies = 1
;session.save_path = "c:\tmp" [purposely commented out according to 5.1.2 documentation]
; Name of the session (used as cookie name).
session.name = PHPSESSID
; The domain for which the cookie is valid.
session.cookie_domain =

Ideas please?






Similar Threads
Thread Thread Starter Forum Replies Last Post
ch.2- cant upload a file no bigger than 52 MB?? cluce BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 April 30th, 2008 09:08 AM
Chap. 2 Page 52-53 session anmolnandha BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 November 30th, 2006 03:07 PM
Ch2 52-54--passing session variables dprice BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 September 26th, 2005 07:01 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





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