p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)
-   -   passing variables through session (http://p2p.wrox.com/showthread.php?t=28562)

dmlocke April 25th, 2005 05:23 PM

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


anshul April 26th, 2005 06:08 AM

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


forumMember00 April 28th, 2005 02:05 PM

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>


dmlocke April 29th, 2005 10:14 AM

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








Gotaka4 May 4th, 2005 10:35 PM

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


All times are GMT -4. The time now is 05:10 AM.

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