Solved

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

Posted on 2007-12-04
15
1,311 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
Comment Utility
<?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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hmm odd
and in your file
<? session_start(); ?>
is at the very very top with no white space (not even a single space) ?
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 21

Expert Comment

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

Author Comment

by:shahnweb
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I recommend crimsoneditor.com for editing PHP files.
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now