itsjoshbruce,
@itsjoshbruce@phpc.social avatar

Learning how to do a thing.

Pretty sure it’s possible; never tried and haven’t been pulled to do so.

PHP creates sessions. Using cookies, it creates a cookie named: PHPSESSID (or similar).

I’d like to customize this; clean and simple.

Goal: I’d like to not have the PHPSESSID cookie. Not finding it.

Thinking:

  1. Disable session cookie
  2. Implement SessionHandlerInterface
  3. Set mine as the save handler
  4. Pass my session cookie in response header

Feel like I’m missing something.

#PHP

derickr,
@derickr@phpc.social avatar

@itsjoshbruce Maybe set the https://www.php.net/manual/en/session.configuration.php#ini.session.name setting to something that isn't PHPSESSID? You're... going to need a cookie regardless.

bhhaskin,
@bhhaskin@bitsofsimplicity.com avatar

@derickr @itsjoshbruce yeah the cookie itself is not the session data, but just an ID that points at the session data.

derickr,
@derickr@phpc.social avatar

@bhhaskin @itsjoshbruce Yes exactly... so what would you want to do different?

itsjoshbruce,
@itsjoshbruce@phpc.social avatar

@derickr @bhhaskin: Well done!

I didn't know session_name was a thing, and definitely clean for changing the key.

I think this will do the trick of step 1 - change the cookie key. And, step 2 - set custom ID:
session_name($sessionName);

/** Custom ID logic */

session_id($customId);

session_start();

No custom class implementing session handler interface is necessary...at least that I'm aware of as of now

Thank!

bhhaskin,
@bhhaskin@bitsofsimplicity.com avatar

@itsjoshbruce @derickr keep in mind that some hosts will block custom cookies. (https://docs.pantheon.io/cookies#why-isnt-my-cookie-being-savedretrieved)

This is due to caching configurations.

itsjoshbruce,
@itsjoshbruce@phpc.social avatar

@bhhaskin @derickr: Good looking out, and fair.

I'll go with the simple approach first. Make sure it works locally, then deploy it to production and verify it will also work there before getting too far into the rest of the solution.

Nothing sucks more than "it works on my machine" - and, your server being like "I'm not your machine. [insert maniacal laughter here]"

  • All
  • Subscribed
  • Moderated
  • Favorites
  • php
  • GTA5RPClips
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • ngwrru68w68
  • Youngstown
  • everett
  • slotface
  • rosin
  • ethstaker
  • Durango
  • kavyap
  • cubers
  • provamag3
  • modclub
  • mdbf
  • khanakhh
  • vwfavf
  • osvaldo12
  • cisconetworking
  • tester
  • Leos
  • tacticalgear
  • anitta
  • normalnudes
  • megavids
  • JUstTest
  • All magazines