View Full Version : Is wrong have two statements like: <?php session_start(); ?>
leonidassavvides
01-05-2009, 11:06 AM
Is wrong have two statements like:
<?php session_start(); ?>
in a document ?
34.<?php session_start(); ?>
the error below appears at
http://www.poliscarhire.com/administration/webmaster/contact-webmaster.php
has any to do with https:// ? No session var above line 34 ...
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/p/o/l/polisch123/html/administration/webmaster/contact-webmaster.php:7) in /home/content/p/o/l/polisch123/html/administration/webmaster/contact-webmaster.php on line 34
l_kris06
01-05-2009, 02:35 PM
From an output standpoint, its not wrong. Once the parsing starts and on the first encounter of session_start() in a script, the headers will be sent for that particular page(stand alone script), any further session_start() encounters will just be ignored and will result in a warning, and ideally this will have no effect on output.
You can use <?php error_reporting(0); ?> on ur script to hide these warnings/errors.
Best,
Kris
JasonDFR
01-05-2009, 06:30 PM
I don't believe the errors you are getting are caused by having two session_start(); on your page. I believe that something must be getting sent to the user's browser prior to the first session_start(); call.
Remember, there can be nothing sent to the user prior to calling session_start(); Not even one space.
For example, the following put at the top of a file won't work
<?php session_start(); ?>
because there is a space in front of <?php .
You either have a space, tab, or some html being sent out prior to the first session_start();
I think.....
If you could post all the php code for that page, we could be sure.
Good Luck,
Jason
l_kris06
01-06-2009, 02:13 PM
Hi JasonDFR,
I do not think having session_start(); anywhere even in the middle of a script with or without space will have the effect as what you have suggested. The following code will still print "Hello World".
<?php
error_reporting(1);
$_SESSION['msg'] = "Hello World";
session_start();
echo $_SESSION['msg'];
?>
@leonidassavvides,
I think its because of duplicate usage of session_start();
Rgds,
Kris
JasonDFR
01-06-2009, 02:22 PM
White space or HTML code before the <?php tag will result in the error he is getting when you call session_start();
I was not referring to any whitespace inside the <?php block. That is why I said "sent to the user." I probably should have said browser.
Regarding calling session_start(); twice:
http://www.php.net/function.session-start
"As of now, calling session_start() while the session has already been started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored."
His error is a warning, not E_NOTICE. His page has sent header information to the browser prior to calling the first session_start();
I am sticking to my previous diagnosis.
Maybe some of the more experienced guys will chime in here.
JasonDFR
01-06-2009, 02:50 PM
Hi JasonDFR,
I do not think having session_start(); anywhere even in the middle of a script with or without space will have the effect as what you have suggested. The following code will still print "Hello World".
<?php
error_reporting(1);
$_SESSION['msg'] = "Hello World";
session_start();
echo $_SESSION['msg'];
?>
And by the way, your code above will not output "Hello World". The session has to be started before you set any session variables.
l_kris06
01-06-2009, 03:04 PM
You are right, Thanks for pointing out.
<?php
session_start();
error_reporting(1);
$_SESSION['msg'] = "Hello World";
session_start();
echo $_SESSION['msg'];
?>
@leonidassavvides,
I think at line 34, u have used another session_start().
Can you post the code for "contact-webmaster.php".
Best,
Kris
JasonDFR
01-06-2009, 03:14 PM
Yeah, post the php source for that page.
l_Kris,
Having two session_start(); will not result in the error he is getting. Have you visted his page and read the error at the top of it?
Most php configurations have level E_NOTICE messages turned off by default, thus putting two session_start(); in one page will not result in any error message being sent to the browser.
I am sure his error is not caused by two session_start(); calls. If I am wrong I'll definitely learn something new.
Post the code please.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.