Re: right place to start a session?
| From: | Padraig Kitterick | Date: | Sat, 27 Apr 2002 17:37:39 +0000 |
| Subject: | Re: right place to start a session? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-94923@lists.php.net to get a copy of this message | ||
The session_start() needs to come before any code outputs anything to the browser, so in your case you need to put it before the <html> and <body> tags:
<?php
session_start();
?>
<html>
<body>
<?
etc...
Padraig
Kirk Babb wrote:
Here's my code:
<html>
<body>
<?php
//trying to start a session right here for the usr and pwd variables
session_start();
session_register("usr", "pwd");
if (isset($login)):
?>
<FORM ACTION='<?php echo($PHP_SELF); ?>
etc., etc where the usr enters their usrname and pwd but I get the following errors:
Warning: Cannot send session cookie - headers already sent by (output started at c:\program files\apache group\apache\htdocs\newsadmin\news.php:3) in c:\program files\apache group\apache\htdocs\newsadmin\news.php on line 5
Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\newsadmin\news.php:3) in c:\program files\apache group\apache\htdocs\newsadmin\news.php on line 5
Have tried moving the session to the next part of the script after the form posts to self with no success. I would like to "keep" the usr and pwd variables for use later since it involves multiple queries to MySQL, right now I have to have the information entered "AGAIN!" and I know that is a pain for users. Please help me out - there are several <form>'s in the script using $PHP_SELF and it seems sessions is the way to go. I'm in need of a good samaritan here...
Thanks! -Kirk