1

I got the following warning messages as shown in picture which i believe is due to addition of an extra session variable (session_start) so what i want is that i need to hide that warning. enter image description here

Actually if i didn't give session at the beginning to get the user session but if it not given then session is not set but when added it give warning. What may be the problem to be?

Code:

    <?php
    session_start();
    include("connect/config1.php");
?>
hakre
  • 193,403
  • 52
  • 435
  • 836
Kundan Raj
  • 77
  • 1
  • 6
  • 1
    So you just want to hide the warning instead of actually fixing it? I hope you're not being paid for this work... – Bojangles Sep 05 '12 at 12:20

2 Answers2

4

You have to place session_start() at the beginning of your document. There has to be no output before this call.

Hiding the message wouldn't solve your problem.

If you only want to hide the warnings:

<?php
ini_set('error_reporting', 0);
ini_set('display_errors', 0);
?>

Look at your fullsearch.php, there probably is a blank line at the beginning (before <?php). Remove it.

Jens
  • 2,050
  • 1
  • 14
  • 30
  • 1
    Congratulations on advising the OP how to shoot himself in the foot. – raina77ow Sep 05 '12 at 12:25
  • I disagree. My 'advise' was to solve the problem with a hint at how to do it. Nevertheless, sometimes it is useful to hide warnings (not in development and probably not with this error) and thus I answered the question. – Jens Sep 05 '12 at 12:29
  • I see your reasons, but disabling error_reporting without logging these errors (by any means) is a very dangerous policy. And, unfortunately, I've met my share of code where all the trash was just swept under the carpet - not without consequences. – raina77ow Sep 05 '12 at 12:36
2

Never try to hide warnings in development environment: they're tremendously useful in hunt for bugs. For example, without this particular warning you'd probably never know why your session-related headers were actually not sent (in other words, why session doesn't work).

Eliminate the reason for the warning shown instead. This particular warning is, most probably, caused by the rogue whitespace that crawled in front of your trusty <?php code delimiter. That means the server have already started to output something to the client, yet you want them to get back to sending of the headers...

So check you files and make sure nothing is echoed before session_start() is called. This discussion would probably be quite helpful. )

UPDATE:

In fact, the code you've quoted in the question has it quite clearly:

   <?php
    session_start();
    include("connect/config1.php");
?>

See, <?php is preceded by whitespace here. That means the server will actually send these symbols (in the HTTP response body), and only then starts to parse the script itself. But then it'll be instructed to send headers - and cries foul with this warning.

The solution is simple: remove the whitespace. This way not only the warning will be gone, but also session will start to work. )

Community
  • 1
  • 1
raina77ow
  • 103,633
  • 15
  • 192
  • 229