Chat

php error: Warning: session_start(): Cannot send session cookie [duplicate]

When i tried my chatbox in my html website a warnings appeared. Warning: session_start(): Cannot send session cookie — headers already sent by (output started at /home/bitmsfgx/public_html/chat/index.php:8) in /home/bitmsfgx/public_html/chat/index.php on line 10 Warning: session_start(): Cannot send session cache limiter — headers already sent (output started at /home/bitmsfgx/public_html/chat/index.php:8) in /home/bitmsfgx/public_html/chat/index.php on line 10 index.php

      

Please enter your name to continue:

'; > if(isset($_POST['enter'])) < if($_POST['name'] != "")< $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name'])); >else< echo 'Please type in a name'; > > ?> else < ?>

Welcome,

Exit Chat

?> User ". $_SESSION['name'] ." has left the chat session. "); fclose($fp); session_destroy(); header("Location: index.php"); //Redirect the user > ?>
(".date("g:i A").") ".$_SESSION['name'].": ".stripslashes(htmlspecialchars($text))." "); fclose($fp); > ?> 
/* CSS Document */ body < font:12px arial; background-color: #ffffff !important; text-align:center; padding:35px; >form, p, span < margin:0; padding:0; >input < font:12px arial; >a < color:#0000FF; text-decoration:none; >a:hover < text-decoration:underline; >#wrapper, #loginform < margin:0 auto; padding-bottom:25px; background:#EBF4FB; width:504px; border:1px solid #ACD8F0; >#loginform < padding-top:18px; >#loginform p < margin: 5px; >#chatbox < text-align:left; margin:0 auto; margin-bottom:25px; padding:10px; background:#fff; height:270px; width:430px; border:1px solid #ACD8F0; overflow:auto; >#usermsg < width:395px; border:1px solid #ACD8F0; >#submit < width: 60px; >.error < color: #ff0000; >#menu < padding:12.5px 25px 12.5px 25px; >.welcome < float:left; >.logout < float:right; >.msgln

Источник

I have this strange problem when i call the parent::setUp() on my TestCase class for unit test a class when i run phpunit it throw me this error:

1) MatchRequestRepositoryTest::test_find_requests_by_match_id ErrorException: session_start(): Cannot send session cookie — headers already sent by (output started at /var/www/project.dev/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:459)

You’ll have to share the contents of your test. Also, is your application doing any direct manipulation of sessions, either via native session_ function calls or Session:: ?

4 Answers 4

One way to handle this in PHPUnit is to send output to stderr instead of stdout as is demonstrated by this answer.

Or by adding stderr=»true» in your phpunit.xml as is pointed out in this comment.

I know this is an old thread, but the problem i have on this solution is that it does not generate a junit.xml file from phpunit.xml for my unit test. I guess it is because it outputs to stderr instead of stdout.

@xCHAN that’s an interesting caveat! I’d never thought about that side effect. You should post a solution if you discover a better option and ping me when you do.

(UPDATE: Thanks to comment by Louis Charette, this will only work in php 7.1 and earlier (and reading the bug report, it sounds like a regression they don’t intend to fix. The better solution is therefore Jeff Puckett’s (https://stackoverflow.com/a/38045422/841830), of giving the —stderr flag on the commandline to phpunit . This keeps stdout for your code, stderr for phpunit, and so they don’t clash.)

The problem is that you have some code, perhaps deep in the framework you use, that calls session_start() . That, in turn, wants to send a cookie. But PHPUnit has already started writing output to stdout.

The point to understand here is that this is just a unit test, no-one cares about the header. So just suppress the error message. And the way you do that, without altering the system-under-test, is to call session_start() in your own unit test (either before parent::setUp() or inside that setUp function). And use the @ prefix to suppress errors. e.g.

Источник

Warning: session_start() [function.session-start]: Cannot send session cookie — headers already sent by [duplicate]

I have an error that displays on my PHP login form, when I upload it to my server. It was working perfectly on my localhost, but when I upload it to server it gives me this error:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 45 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 45 Warning: Cannot modify header information - headers already sent by (output started at /home/shopping/public_html/biblioteka/index.php:10) in /home/shopping/public_html/biblioteka/index.php on line 49 
        
Корисничко име:

Лозинка:

Источник

Php Session header already send error [duplicate]

The error is coming from the file C:\xampp\htdocs\netsentries\f\includes\functions.php:1 . Are you sure you don’t have a call to the header() function in that file?

6 Answers 6

You can’t session_start after you’ve outputted any HTML at all. Move the session_start call up to the top, and keep a variable for what to echo later. Anything not in counts, even your include file.

You need to put session_start() before anything outputs on the page.

  

Login

Username

Password


else < include('includes/config.php'); $data['username']= $_POST['username']; $data['password']= md5($_POST['password']); connect($db_name,$db_user,$db_pass,$db_host); $query= "select * from user where username='" . $data['username'] . "' AND password='" . $data['password'] . "'"; $result=mysql_query($query); //check that at least one row was returned $rowCheck = mysql_num_rows($result); if($rowCheck >0) < while($row = mysql_fetch_array($result)) < session_register($data['username']); //successful login code will go here. //echo 'Logged in!'; >> else < echo "Failed!"; >> ?>

If you were trying to use any function that modifies the header (like header or session_start ), you need to make sure that nothing was outputting beforehand, even whitespace — or else you will get that error.

Halfway down you’re having

But you don’t want any output before that. And you have -in the very least- this allready sent:

PUt the session on the top 😀

look for white space in that file.

in particular after the ?> at the end of the file there is often white space.

so omit the closing ?> at the end of your files.

Make sure there is absolutely nothing being output before your session call — even whitespace. (See Pekka’s comment 🙂 )

This question is in a collective: a subcommunity defined by tags with relevant content and experts.

Источник

«Warning: session_start() [function.session-start]: Cannot send session cookie — headers already sent» when calling session_start() first in file [duplicate]

Warning: session_start() [function.session-start]: Cannot send session cookie — headers already sent by (output started at . /test.php:1) in. /test.php on line 10 Warning: session_start() [function.session-start]: Cannot send session cache limiter — headers already sent by (output started at . /test.php:1) in. /test.php on line 10

4 Answers 4

If you have saved your file in UTF-8 format, be sure to check if it is UTF-8 without BOM.

Good call. I bet you’re right. I first learned about the byte order mark when I opened a script in nano and it had a strange character at the beginning.

I resaved my file in UTF-8 no BOM but it didnt solve it. I remember I had this prob before and it sure sound like it. Do I have to change anything else or should the resave solve it? How about doctype, mysql connection etc? Or is it simply something else?

resaving solved it! Still, do I need to change anything else or does the utf8 no bom only apply to the encoding the file is saved as?

Happy to hear it solved it. If you want to use UTF-8, be sure to apply it to META content-type, php header Content-type, MySQL connection, collation in your database and tables (and the encoding of your PHP files if you want to use UTF-8 constants). And anything I can’t think of when I’m drunk.

Источник

Читайте также:  Анализ данных python ниу вшэ
Оцените статью