note 23046 added to ref.session
| From: | sponger@php.net | Date: | Mon, 08 Jul 2002 06:30:41 +0000 |
| Subject: | note 23046 added to ref.session | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32723@lists.php.net to get a copy of this message | ||
After lots of headaches i finally found a way to pass session ID's without having to edit the
URL, and letting PHP do it for me. For example, if i use a function to print links, i can append
$SID instead of SID. When formatting the URL, PHP will tag on ? and & where necessary, incase i
pass a URL with variables already. Take a look at the function below.
/* make_link()
Returns a link. */
function make_link($url, $text=false, $target=false, $extras=false)
{
return sprintf
(
'<a href="%s"%s%s>%s</a>',
$url.$SID,
($target ? ' target="'.$target.'"' : ''),
($extras ? ' '.$extras : ''),
($text ? $text : $url)
);
}
If i pass a URL for example, /index.php?var=value. PHP will tag on the SID and apply a & after
value, ie. /index.php?var=value&session_id=<session id>. And if i just pass /index.php,
PHP will tag on ?session_id=<session id>. I've been told this wont work (without the
person even testing it), but it works fine for me, and takes less code if you were to format the
string afterwards.
--
http://www.php.net/manual/en/ref.session.php
http://master.php.net/manage/user-notes.php?action=edit+23046
http://master.php.net/manage/user-notes.php?action=delete+23046
http://master.php.net/manage/user-notes.php?action=reject+23046