Solved

PHP 5: session_start() without any other statement still outputs "Cannot send session..." warning

Posted on 2007-12-04
15
1,342 Views
Last Modified: 2013-12-13
Here is my test.php.
<?php
session_start();
phpinfo();
?>

It displays the 2 lines of Warning "Cannot send session..." and then displays phpinfo correctly.
As you see there is nothing (not even a space), before session_start()

php.ini file has : session.save_path = "C:\dev\A_M_P\tmp"
I do see that the session file is created in this directory EVERYTIME I load the test page.

I googled, and people say I might have some character at the end of Config.php's ?>.
I verified and I don't have.

This is my first time using session for PHP. I do see that a new session file is created every time I acces the test.php. What else could be wrong unless XAMPP package is buggy?

Steve
0
Comment
Question by:shahnweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20407882
<?php session_start(); ?>
<?php echo "test"; ?>


save that as a php file, does it work or do you still get error?
0
 

Author Comment

by:shahnweb
ID: 20407946
Yes, exactly same errors.  And I always see the output(in this case 'test'). Session file is keep created un the tmp directory..
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 100 total points
ID: 20407975
ok, go to view source in your browser, can you see anything before the 'test'??
Remember to check that 'test' is the very first line, and has no spaces or returns (newline) before it.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:shahnweb
ID: 20408119
The following below of the dotted line is the exact cut and past from the view source.
I don't see anything except the error mesage.
------------------------------
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at C:\webroot\goodvibe\php\test.php:1) in <b>C:\webroot\goodvibe\php\test.php</b> on line <b>1</b><br />
<br />
<b>Warning</b>:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at C:\webroot\goodvibe\php\test.php:1) in <b>C:\webroot\goodvibe\php\test.php</b> on line <b>1</b><br />
test
0
 
LVL 10

Expert Comment

by:wildzero
ID: 20408299
Just wondering, do you have something in your .htaccess / apache config where it is always loading another PHP file first.

something like
php_value auto_prepend_file "somefile.php"
0
 

Author Comment

by:shahnweb
ID: 20408392
I scanned the directory and found total 3 .htaccess files with the contents like below.
I'm not sure what Deny from all means here, but I don't find any thing appending output.  Both Apache and MySQL are from XAMPP package for my Windows XP.

#1 C:\dev\A_M_P\htdocs\forbidden\.htaccess
AuthType Basic
AuthName "FORBIDDEN AREA"
AuthUserfile "../htdocs/forbidden/.htpasswd"
Require valid-user

#2 C:\dev\A_M_P\phpMyAdmin\libraries\.htaccess
# This folder does not require access over HTTP
# (the following directive denies access by default)
Order allow,deny

#3 C:\dev\A_M_P\htdocs\xampp\sqllite\.htaccess
Order deny,allow
Deny from all
0
 
LVL 10

Assisted Solution

by:wildzero
wildzero earned 100 total points
ID: 20408403
Hmm odd
and in your file
<? session_start(); ?>
is at the very very top with no white space (not even a single space) ?
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20408422
very odd indeed. Try the script i posted above on another host, see if it works?
0
 

Author Comment

by:shahnweb
ID: 20409073
I found the solution!
The cuprit was my SEPY ActionScript editor.(which supports PHP highlighting).
I have compared the same PHP statement written by notepad, and SEPY adds garbages at the beginnig as below. I don't know why SEPY does this, but I will not use this editor again.

BTW, can anybody suggest a good editor for PHP and ActionScript?  (I have Adobe Master Suite CS3)
Thanks nizsmo and wildzero for your effort.

C:\webroot>type test.php
<?php session_start(); ?>
<?php echo "test"; ?>
C:\webroot>type testSepy.php
)W<?php session_start(); ?>
<?php echo "test"; ?>

0
 
LVL 21

Assisted Solution

by:nizsmo
nizsmo earned 100 total points
ID: 20409472
i see! glad you found solution!

My suggestion for PHP editing would be Zend Studio!
http://zend.com/en/products/studio

In my opinion by far the best editor there is for PHP, you can also to a certain extent use Dreamweaver, PHPEclipse, etc...

Hope this helps! :)
0
 
LVL 10

Assisted Solution

by:wildzero
wildzero earned 100 total points
ID: 20410089
Yay :-)
http://www.eclipse.org/pdt/
That is the editor I have been using lately, Zend Studio is going to start using it (as you can see from Zends beta release's). However eclipse is free!
0
 
LVL 9

Assisted Solution

by:tkalchev
tkalchev earned 50 total points
ID: 20450652
SEPY is saving the .php files in UFT-8 format, php still have some problems executing them ... Change the settings of your editor and specify an encoding different then UTF-8
0
 

Author Comment

by:shahnweb
ID: 20454223
SEPY also works if I save it using ASCII mode.

The question now is how to input non-ASCII foreign languge error message in PHP?

For example, if I include "error.php" that includes UTF-8 based error message in a php file that uses $xml->asXML(), the statement fails since the include file contains 'garbage' bytes(2) what tags UTF-8 file.

0
 
LVL 9

Expert Comment

by:tkalchev
ID: 20455934
Try to write only the messages into an external unicode file (.txt for example), then load it in the php code, using file_get_contents. Leave the php source in ASCII. This should work.
0
 
LVL 1

Expert Comment

by:a53mp
ID: 21224408
I recommend crimsoneditor.com for editing PHP files.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question