I can't use sessions in PHP

I’m very tired and angry of this that I can’t use sessions in PHP. Can you tell me what am I doing wrong or this is server issue? I was using local server before and I didn’t have problems…

Sessions should work perfectly fine on InfinityFree. Can you please elaborate on the problem you experience? If you can point our exactly what doesn’t work or even include example code snippets we can check, we can help you figure this out.

I have the same problem, my login.php has session_start(); in it, and when I try to go to that file, it takes me to the 403 error page, forbidden.
I already checked the permissions for read, write and executing, which were fine.
Only when I removed session_start(); I could actually visit the page.
I put it back in just to be sure, and indeed it took me to the forbidden page again, so I figured it could only be the session_start();
I’m not sure if Kemoty is running into the same problem?

we need your code

because in most cases users forget to move session_start ();
above <! DOCTYPE html>

it must be the very first thing in your document, before any HTML tags

in any case we need more info/code

The session_start(); is on the very first line like this:

I checked your code and I think I see the issue.

I see you use session_start() correctly on the login submit page. However, you need to call that function on every page where you need to access the session. So the session is set correctly after logging in, but it’s not loaded on the gebruiker.php page.

If you add a session start to the gebruiker.php page, or make sure that sessions are enabled in the general login checker page, and it should work.

1 Like