PHP session_start() problem, I am done pulling my hair out

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
So I'm trying to use sessions for a shopping cart (if you know a better way please enlighten me) so all the users are indexed by the session ID.

The general flow of my code is the following:

<!Document declaration
<html ... >
2 meta tags

then we get into the body. This is the standard layout for EVERY page. Once I get into the body I set the variable $headerfile and then include('header.php');

No matter where I put <?php session_start(); ?>, either at the beginning of the index file or at the beginning of the header file, I get an error that session_start() has already been called. When I put it at the beginning of index.php, it states that line 1 of index.php is the line that already called it... well gee thanks!

Any ideas? Either I need to figure this out or abolish session_id's as a way to do my shopping cart. I wanted to avoid cookies, but even if I used cookies, how do I know which user has what items without a session ID?

Thanks for any help!
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
I think I figured out the reason but not sure how to fix it... it looks like index.php is being executed twice... once on my "absolute hosting path" then once again in the folder it is actually being hosted in. This is all I can come up with.

When I get the error it shows that it has already been executed, but it shows my path written out with the absolute path, not sure if this matters.

EDIT: I take that back, the paths are the exact same. So it is saying index.php is causing the problem even though there are no spaces or anything in the beginning of the file.

My very first line is:

<?php session_start(); ?>
 
Last edited:

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Did you perhaps set session auto start in your PHP configuration?

No. Here are my session configs:

session

Session Support enabled
Registered save handlers files user sqlite
Registered serializer handlers php php_binary wddx

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path no value no value
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0


Also I found out last night I can't even use setcookie(); . I'm wondering if it is a read / write issue to a directory, but doesn't the cookie command write to the client and not the host? Or is the cookie stored on the host too?
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
Are you by any chance editing in windows? I've had odd issues with session due to the byte order marker being set.
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Are you by any chance editing in windows? I've had odd issues with session due to the byte order marker being set.

I am. Using notepad++, I opened the file in standard notepad and didn't notice anything that looked different.

What program can I use?

EDIT:

I changed the setting in notepad++ to save file in UTF-8 without BOM and still no luck.

EDIT EDIT:

SUCCESS! I created a new file in Unix format and chose to do UTF-8 without BOM and now it works! You are a life saver. I cannot believe this was the issue... as decent as I am at programming I would have never figured this out. Thanks again!
 
Last edited:

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
That is a strange one. I would never had guessed that.

Yeah no kidding right?

What a pain in the neck too as I had to change over any page that had the ability to buy a product from windows structure to unix. Good thing this was figured out early on and now I'm done. On to finishing my cart!

You know years ago I first started learning about computers and this site taught me everything. Years later it still doesn't let me down! Love it.
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
Yeah, that one's a real "huh?" kind of thing. Took a while to figure that out, wouldn't have at all if it hadn't been a french-language site I was working on. Needed UTF and got me looking in the right place. It's certainly high on the list of most bizarre things I've encountered.