print '<a href="train.php">Take the A Train</a>';
If sessions are enabled, but a user doesn't accept
cookies, what's sent to the browser is something
like:
<a href="train.php?PHPSESSID=2eb89f3344520d11969a79aea6bd2fdd">Take the A Train</a>
In this example, the session name is PHPSESSID and
the session ID is
2eb89f3344520d11969a79aea6bd2fdd. PHP adds those
to the URL so they are passed along to the next page. Forms are
modified to include a hidden element that passes the session ID.
Redirects with the Location header
aren't automatically modified, so you have to add a
session ID to them yourself using the SID
constant:
$redirect_url = 'http://www.example.com/airplane.php';
if (defined('SID') && (! isset($_COOKIE[session_name()]))) {
$redirect_url .= '?' . SID;
}
header("Location: $redirect_url");