Date: 11/01/99
- Next message: Kristian Koehntopp: "Re: [PHPLIB-DEV] Form problem"
- Previous message: Kirill Maximov: "[PHPLIB-DEV] Form problem"
- In reply to: Kirill Maximov: "[PHPLIB-DEV] Form problem"
- Next in thread: Kristian Koehntopp: "Re: [PHPLIB-DEV] Form problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I use the following functions, which help generalize URLs to some extent,
providing for GET sessions, POST sessions and COOKIE sessions. These need
to be turned into a proper class, which I hope to do eventually.
get_url($url, $param)
get_self_url($param)
get_form_hidden($param)
In a form, use $PHP_SELF for the URL, which provides a clean URL without
any query string.
In each case, $url is a plain URL, either relative or absolute, and $param
is an associative array (in the form of name => value) for any additional
parameters that you would like to pass in the url or in the session.
# selfurls.inc:
# (note that $session_name is a global variable indicating your session
string # (e.g. Poe_Session, or Example_Session).
#
# (note also that for PHPLIB to behave correctly, you do need to copy #
$HTTP_POST_VARS[$session_name] to $HTTP_GET_VARS[$session_name] on each
page # before page_open())
$session_name = 'Example_Session';
function get_params($param='') {
global $DEBUG_LEVEL, $HTTP_GET_VARS, $session_name;
$dbg = getenv('PATH_INFO');
if ($dbg && eregi('debug([0-9]+)', $dbg, $dbgm)) {
$DEBUG_LEVEL = $dbgm[1];
}
if (!$param) $param = array();
$param[DEBUG_LEVEL] = $DEBUG_LEVEL;
$session_id = $HTTP_GET_VARS[$session_name];
if ($session_id) {
$param[$session_name] = $session_id;
}
return $param;
}
function get_self_url($param='') {
return get_url($GLOBALS[PHP_SELF],$param);
}
function get_url($url,$param='') {
$pairs = array();
$qs = '';
$param = get_params($param);
reset($param);
while (list($k,$v) = each($param)) {
$pairs[] = "$k=$v";
}
$qs = join('&', $pairs);
if ($qs) $url .= "?$qs";
return $url;
}
function get_form_hidden($param='') {
$param = get_params($param);
$sess = '';
reset($param);
while (list($k,$v) = each($param)) {
$sess .= "<input type=hidden name=\"$k\" value=\"$v\">\n";
}
return $sess;
}
At 03:32 PM 01/11/99 +0300, Kirill Maximov wrote:
> hi,
>
> I want to offer one more function for class Session which should be
>used in
> the following situation:
> 1. We have a FORM on a page which uses "GET" method.
> 2. We're want to be sure that it will work with session variables even
>if
> user have cookies off.
>
> The solution is simple - pass session_name as additional variable of
>form.
> Why can't we offer a function which will insert appropriate
> <INPUT> hidden field iside the form ?
>
> We use such a function in our work - it seems to be useful:
>
>
>//---------------------------------------------------------------------------
>
> // Class Session
> //Function for adding hidden field with session ID in form
> //if cookies off
> function hidden_id()
> {
> switch ($this->mode)
> {
> case "get":
> echo "<INPUT TYPE=\"HIDDEN\" NAME=\"" . $this->name .
>"\" VALUE=\"" . $this->id. "\">";
> }
> }
>
> Regards,
> KIR
>
>--
>----- ----- ----- ----- ----- ----- ----- -----
> Kirill Maximov; maximov <email protected> ICQ: 14796643
> Chief of Software Development Department,
> Astrive, Inc.
>
>
>-
>PHPLIB Developers Mailing List. Send messages to
<phplib-dev <email protected>>.
>To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in
>the body, not the subject, of your message.
>
-- Michael Graham magog <email protected> - PHPLIB Developers Mailing List. Send messages to <phplib-dev <email protected>>. To unsubscribe, send "unsubscribe" to <phplib-dev-request <email protected>> in the body, not the subject, of your message.
- Next message: Kristian Koehntopp: "Re: [PHPLIB-DEV] Form problem"
- Previous message: Kirill Maximov: "[PHPLIB-DEV] Form problem"
- In reply to: Kirill Maximov: "[PHPLIB-DEV] Form problem"
- Next in thread: Kristian Koehntopp: "Re: [PHPLIB-DEV] Form problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

