Please note that this will not work if the client has cookies disabled, as you are not url-rewriting (attaching the session id to your url string) nor trying to pick up the session on each page.
Something like this would be fine:
I have three main functions for url-rewriting I will always use:
function print_form_action($url)
{
// tags on SID if present
// returns something like.. action="/index.php?sid=ASA129387AKLJS"
global $HTTP_GET_VARS, $HTTP_POST_VARS;
if ( isset($HTTP_GET_VARS['sid']) )
$sid = $HTTP_GET_VARS['sid'];
else if ( isset($HTTP_POST_VARS['sid']) )
$sid = $HTTP_POST_VARS['sid'];
else
unset($sid);
$action = "action=\"";
$action .= $url;
if ( isset($sid) )
$action .= "?sid=" . $sid;
$action .= "\"";
return $action;
}
function print_link($base_url, $query_string,
$link_text, $extras = "")
{
global $HTTP_GET_VARS, $HTTP_POST_VARS;
// syntax to call: echo print_link($base_user_url,'admin=edit_content','Admin Area')
if ( isset($HTTP_GET_VARS['sid']) )
$sid = $HTTP_GET_VARS['sid'];
else if ( isset($HTTP_POST_VARS['sid']) )
$sid = $HTTP_POST_VARS['sid'];
else
unset($sid);
$link = "<a href=\"";
$link .= $base_url;
if ( isset($sid) )
$link .= "?sid=" . $sid;
if ($query_string) {
// make sure they want to go somewhere past main script
if ( strpos($link,"?") != true )
$link .= '?';
else
$link .= "&";
}
$link .= $query_string;
$link .= "\" $extras>$link_text</a>";
return $link;
}
function redirect($ref, $value, $home, $msg = "") {
global $HTTP_GET_VARS, $HTTP_POST_VARS;
if ( isset($HTTP_GET_VARS['sid']) )
$sid = $HTTP_GET_VARS['sid'];
else if ( isset($HTTP_POST_VARS['sid']) )
$sid = $HTTP_POST_VARS['sid'];
else
unset($sid);
// syntax to call: redirect('refreshtime','where to go past
//beginning (optional)',$home)
// example to redirect to index.php?admin=edit_content: redirect
//('3','admin=edit_content',$home)
flush();
$url = $home;
if ( isset($sid) && strlen($sid) > 2 )
$url .= "?sid=" . $sid;
if ($value) {
// make sure they want to go somewhere past main script
if ( strpos($url,"?") != true )
$url .= '?';
else
$url .= "&";
$url .= $value;
}
echo "
<html>
<head>
<meta HTTP-EQUIV=\"refresh\" CONTENT=\"$ref;URL=$url\">
</head>
<body>
$msg
</body>
</html>
";
flush();
}
And at the top of EVERY page, I have this:
if ( isset($HTTP_GET_VARS['sid']) )
{
$sid = $HTTP_GET_VARS['sid'];
session_id($sid);
session_start();
}
else if ( isset($HTTP_POST_VARS['sid']) )
{
$sid = $HTTP_POST_VARS['sid'];
session_id($sid);
session_start();
}
This will ensure that you are compliant with people who do not use cookies.
cheers,
k.