Search code examples
phpsessionoutput-buffering

Is there a fast way to append the session name to all links?


Is there a fast and efficient way to append a ?sid=asdasdasd or a &sid=asdasdasd to all urls on a page using PHP? Should I use output buffering for this?

I'm trying to have something like:

<a href="/something.php">hello</a>

to change to:

<a href="/something.php?sid=somethingrandom">hello</a>

Solution

  • In your PHP configuration, turn off session cookies, and turn on transparent sid support, which will automatically rewrite links to include a session ID.

    Note that URL-based sessions are considered a bad practice.