Stupid Errors with session_start()
Moderator: General Moderators
Stupid Errors with session_start()
I used sessions in my php code and i get the following error:
Warning: Cannot send session cookie - headers already sent by (output started at /home/hxotpon.net/w/connect.inc:9) in /home/xxxxx.net/www/music/index.php on line 15
Warning: Cannot send session cache limiter - headers already sent (output started at /home/hxotpon.net/w/connect.inc:9) in /home/xxxxx.net/www/music/index.php on line 15
Warning: Cannot add header information - headers already sent by (output started at /home/hxotpon.net/w/connect.inc:9) in /home/xxxxx.net/www/music/index.php on line 16
Let me explain myself:
There is not any output before and my code complies with any suggestion in other forums/post .
I tried to run any tutorial with sessions and i get the same errors so i believe that the problem is in the server. Php.ini or php compilation is the key.
Can anyone suggest any misconfiguration that disallows proper use of sessions?
Also can anyone send me his php.ini inorder to compare with mine!
Thanx guys!
Warning: Cannot send session cookie - headers already sent by (output started at /home/hxotpon.net/w/connect.inc:9) in /home/xxxxx.net/www/music/index.php on line 15
Warning: Cannot send session cache limiter - headers already sent (output started at /home/hxotpon.net/w/connect.inc:9) in /home/xxxxx.net/www/music/index.php on line 15
Warning: Cannot add header information - headers already sent by (output started at /home/hxotpon.net/w/connect.inc:9) in /home/xxxxx.net/www/music/index.php on line 16
Let me explain myself:
There is not any output before and my code complies with any suggestion in other forums/post .
I tried to run any tutorial with sessions and i get the same errors so i believe that the problem is in the server. Php.ini or php compilation is the key.
Can anyone suggest any misconfiguration that disallows proper use of sessions?
Also can anyone send me his php.ini inorder to compare with mine!
Thanx guys!
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Reply:
You are right i write:twigletmac wrote:There is output before and it is in connect.inc on line 9 - what are the first 10 lines of connect.inc?
Mac
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
function connect_db() {...
I have 2 blank lines, i will fix it. Do you see anything else which seems wrong?
The rest of the code is elements for connection to the db
On the other hand, why all the tutorials about sessions i tested made the same errors despite the fact they didn't connect to connect.inc?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
This is output:
you have to have session_start() before any output is sent to the browser, output is HTML, javascript, blank lines, spaces before the opening <?php tag, etc.
Mac
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7">
</head>
<body bgcolor="#FFFFFF" text="#000000">Mac
You are right, i tested with <?php ?> before <html><title>...twigletmac wrote:This is output:you have to have session_start() before any output is sent to the browser, output is HTML, javascript, blank lines, spaces before the opening <?php tag, etc.Code: Select all
<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-7"> </head> <body bgcolor="#FFFFFF" text="#000000">
Mac
and it works.
Thanx for your time Mac
The Conclusion for me is:
The rule is to write <?php ?>
with sessions related code before and outside the html area.
Then sessions are passed automatically to another page when i hit a link on that page.
If i'm wrong to anything just correct me!
Last edited by dimitris on Wed Jan 14, 2004 5:27 am, edited 1 time in total.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
That's good.dimitris wrote:You are right, i tested with <?php ?> before <html><title>...
and it works
You got it.dimitris wrote:So the rule is to write <?php ?> with sessions related code before and outside the html area
Exactly, although if you want to access anything from the session, you'll need session_start() in the next page too.dimitris wrote:Then sessions are passed automatically to another page when i hit a link?
Mac
Yes, i always use session_start()twigletmac wrote:That's good.dimitris wrote:You are right, i tested with <?php ?> before <html><title>...
and it worksYou got it.dimitris wrote:So the rule is to write <?php ?> with sessions related code before and outside the html areaExactly, although if you want to access anything from the session, you'll need session_start() in the next page too.dimitris wrote:Then sessions are passed automatically to another page when i hit a link?
Mac
I have the very idea that i must write something before a link such as:
<? echo $_SESSION['session_id']; ?> or <? echo $_SESSION['log_status']; ?> in order to pass session values such as session id,username,password OR it is absolutely automatically and you have only to handle them?
Thanks a lot
ADDED NOW:Problem->Solution->Problem
Sorry Merfy's law just occured!
After running the enhanced script other php scripts in the same page (requesting 5 last records from a database) return now die message!
Is there any conflict with the change?
I mention that after the login form is submitted, I use
action="<?php echo $PHP_SELF ?>"
Last edited by dimitris on Wed Jan 14, 2004 5:54 am, edited 2 times in total.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
That's right!I will make some tests until i hit my target!twigletmac wrote:You shouldn't have to add session ids automatically. Best thing you can do is remove that from your URLs and test the links to see what happens - learning by doing.
Mac
Learning by doing!
I will check some tutorials inorder to be more confident with what is going on with sessions...
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
What's your error message?dimitris wrote:ADDED NOW:Problem->Solution->Problem
Sorry Merfy's law just occured!
After running the enhanced script other php scripts in the same page (requesting 5 last records from a database) return now die message!
Is there any conflict with the change?
I mention that after the login form is submitted, I use
action="<?php echo $PHP_SELF ?>"
Mac
Well that's my code:twigletmac wrote:What's your error message?dimitris wrote:ADDED NOW:Problem->Solution->Problem
Sorry Merfy's law just occured!
After running the enhanced script other php scripts in the same page (requesting 5 last records from a database) return now die message!
Is there any conflict with the change?
I mention that after the login form is submitted, I use
action="<?php echo $PHP_SELF ?>"
Mac
<?php require_once ("../../w/connect.inc");
error_reporting(E_ALL); //<? echo $_SESSION['session_id'];
$query4ma = "SELECT id_diskou,title,hxotpon_prod FROM diskoi WHERE hxotpon_prod='Yes' ORDER BY id_diskou DESC ";
$result4ma = mysql_query ($query4ma) or die("Query failed!");
function displayMagsa($result4ma)
{
$a=1;
while(($row = @ mysql_fetch_array($result4ma)) AND ($a<6))
{
printf("<a href="view_each_disko.php?id=%s"<font color="#000000" size="2" face="Verdana">%s. %s </font></a><br>",$row['id_diskou'],$a,$row['title']);
$a++;
}
}
displayMagsa($result4ma);
?>
So I get the error: Query failed , whereas I could see the last 5 records.
That was working normally in the same page before the login form is submitted!
Well! I tried it but the same thing happens again!basdog22 wrote:maybe this: ;?????<?php echo $PHP_SELF ?>
Code: Select all
<?php echo $PHP_SELF; ?>
Are elladara
I thing that there is no use for ; in that statement!
Ela re patrioti!
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
The semi-colon is not necessary but is good to add every time (cuts down on parse errors).
$PHP_SELF should be $_SERVER['PHP_SELF'] as $PHP_SELF is deprecated.
So that we can narrow down the problem a bit better, could you replace:
with
and then post the error message you get.
Mac
$PHP_SELF should be $_SERVER['PHP_SELF'] as $PHP_SELF is deprecated.
So that we can narrow down the problem a bit better, could you replace:
Code: Select all
$result4ma = mysql_query($query4ma) or die('Query failed!');Code: Select all
$result4ma = mysql_query($query4ma) or die('Query failed!'.mysql_error().'<p>'.$query4ma.'</p>');Mac