"Cannot change session name" error

PHP version: 7.4.14
Apache: 2.4.46
Windows 10 Home x64


I’m using a contact form script that I first used with PHP5, but haven’t used for about about 7 years. Everything looks good except for this error:

Warning: session_name(): Cannot change session name when session is active in C:\web\Apache24\htdocs\devsite\contact.php on line 69

This is the code in question:

Line 67 // start session
Line 68 session_start();
Line 69 session_name('contactform');

I’m still getting to know PHP7 after years away from all this, so I thinking it’s something to do with that?

Any help would be much appreciated. :slight_smile:

I’m going to reply to my own post, lol.

I switched the lines around, and it works now.

Line 67 // start session
Line 69 session_name('contactform');
Line 68 session_start();

Just wanted to post this for anyone’s future reference. :slight_smile:

2 Likes

Off-topic:
The current version of PHP is 8.0, so you might want to get to know that and skip 7.

2 Likes

And yet I was advised not long ago in these very forums to NOT move to 8 yet, for various reasons.

If I wanted to be on 8, I would be. So I’m on 7, and when I need help on 7 I would appreciate zero comments about how I should be on 8. wow…

As far as I can see, you weren’t advised not to move to PHP 8 here, it was your decision:

I’ve decided to roll back to PHP7, since 8 isn’t widely supported yet, and because of Microsoft’s odd decision.

The important thing is to ensure you’re using a version that is still supported.

Well, if you are going to ask for help be prepared for advice, you can choose not to accept it - and you can certainly refuse more politely!

4 Likes

But I didn’t ask for advice on which version I should be using, I asked about the one I am using. If someone asked how to fix something on a 2005 Chevy, would you consider it polite to tell them they should buy a newer model? Seriously, it was a simple question, I even posted the solution when I discovered it, unlike a lot of folks who say stuff like “I figured it out”, and never tell what they figured out.

Okay, memory glitch, my apologies. But I knew there was something or someone who cautioned me about 8, so I haven’t gone there yet. Not to mention my host doesn’t yet offer that option.

I do sympathise, I am in same position. PHP 8 not available on my hosting yet and I am reluctant to learn even more new coding practices or inevitable problems. I was just pointing out that people on this forum are genuinely trying to help. I have been on some forums where the arrogance is mind boggling, full of ‘professionals’ with delusions of adequacy!

You will often get suggestions that don’t seem to address the immediate issue but it really is a genuine effort to help. When you are stuck in a problem that is pretty imperative, yes it can be frustrating when someone suggests a totally new approach but it is usually well intentioned - I wish you luck :grinning:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.