Solved

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

Posted on 2007-12-04
15
1,319 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 count occurrences of each item in an array.

947 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now