Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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
 
Old April 25th, 2005, 05:23 PM
Authorized User
 
Join Date: Apr 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default passing variables through session

Hi,

I am working on the Beginning php,mysql and apache book, chapter 2. I am having problems passing a value through a session.
I have typed the code exactly as it say in the book and I keep getting this error:

Warning: Cannot send session cookie - headers already sent by (output started at c:\phpdev\www\phppractise\music review site\movie1.php:2) in c:\phpdev\www\phppractise\music review site\movie1.php on line 3

Warning: Cannot send session cache limiter - headers already sent (output started at c:\phpdev\www\phppractise\music review site\movie1.php:2) in c:\phpdev\www\phppractise\music review site\movie1.php on line 3
Click here to see information about my favorite movie!

I am not sure what is happening here. Can anyone help?

I have checked the php.ini file for the correct session_save_path which seems to be pointing to the right file.

Any ideas whats wrong?

David

 
Old April 26th, 2005, 06:08 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

See http://p2p.wrox.com/topic.asp?TOPIC_ID=29730

 
Old April 28th, 2005, 02:05 PM
Registered User
 
Join Date: Apr 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If the above does not work it could just be a silly problem such as whitespace. You would want to have your <?php in the beginning of your page (no whitespace before it), start your session and whatever php coding, then close it with ?> before you write your <html> tag.

For example:
<?php
session_start();
//php coding here...
?>
<html>
<head></head>
<body></body>
</html>

 
Old April 29th, 2005, 10:14 AM
Authorized User
 
Join Date: Apr 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help, but I have done exactly as you said and it still does'nt work.

I have copied the code exactly as it says in the book:

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

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

I have checked register globals is off and that the php.ini file is pointing to the right temp file for sessions, which is all ok!

It is becoming a bit of a problem now because I really don't know what to do and I can't progress in the "beginning php,mysql and apache" book until I resolve this problem, as sessions are required for the examples in the book.

Wish I new what the problem is???

Many thanks
David







 
Old May 4th, 2005, 10:35 PM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

put
session_start();

at the beginning of your pages...

----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing session variables from login page. captainzorro Classic ASP Components 1 April 23rd, 2008 11:54 PM
Passing session variables from IIs to Tomcat aman thaper Internet Information Services 0 November 14th, 2006 09:34 AM
Passing Session Variables to the Next Page jim.sullivan@telus.net ASP.NET 1.0 and 1.1 Professional 1 August 1st, 2004 06:25 PM
Passing Session Variables to the Next Page jim.sullivan@telus.net Classic ASP Databases 2 August 1st, 2004 01:59 PM





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