Pergunta

I have having a problem where session ids are not being written. Am sorry if this question goes on for a bit long, but I have done quite a few tests to rule out certain things, so thought it was useful to present all of the data that I have.

For each test, I am opening up a new incognito window in Chrome to make sure that cookies/sessions are cleared before starting a new test.

In addition, please note, that the website I am working on has two different languages in two different folders. English and Hebrew.

Everything is working fine in the English side of the site but not in the Hebrew. Some of the 'include' files are in a seperate folder called /php/ which are included both on the Hebrew and English side.

Not sure if relevant, but the .htaccess file contains redirects on both English and Hebrew side which are something like:

RewriteEngine on

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteRule ^categories/(.+) /HE/categories.php?pg=$1&type=$2 [L]

On the php page itself (eg. categories.php), the code starts off:

<?php include_once('header.php');

In header.php, I have:

<?
require_once '../php/config.php';
require_once 'functions.php';

in config.php which is used both on the hebrew and english sides, I have:

<?php
session_start();
echo "--".session_id();

in all cases, the

When I go to the page:

http://www.goo.com/HE/categories/foo

each time I refresh, it echos out a new value for session_id()

In the error log, I am getting:

[23-Oct-2013 04:12:41] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cookie - headers already sent by (output started at /home/foo/public_html/HE/header.php:1) in /home/foo/public_html/php/config.php on line 2
[23-Oct-2013 04:12:41] PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: Cannot send session cache limiter - headers already sent (output started at /home/foo/public_html/HE/header.php:1) in /home/foo/public_html/php/config.php on line 2

Now, I want to stress again, that there is no white space that I am aware of and that the equivalent seems to be working on the english side without a problem.

I have created a file called testsess.php which contains:

<?php
session_start();
echo "--".session_id();

and put it in the HE folder and this works as it should without an error

I am sure that it is something really simple, but been trying different things for hours and hours and am totally stumped.

Foi útil?

Solução 2

You may refer to this SO Question

Probably this is a UTF-8 BOM (Byte-Order-Mark) issue. If windows environment is accessible you can use Notepad++ to remove the BOM:

  1. Open the file in notepad++
  2. In Encoding menu select "Encode in UTF-8 without BOM"
  3. Then save

Outras dicas

Chek if your files are UTF-8. some text editors put a bit of code on begining of the UTF-8 files. Check if there is any extra character at the files you include.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top