<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Maybe, I can only receive emails on this list
;)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Another suggestion where this function would
be helpfull is in say .....</FONT></DIV>
<DIV><FONT face=Arial size=2> admin/topic.php -- I believe $tid and $topic
are variables that are passed as GET or POST vars.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>You need to check for both, post is higher in
presidence and if not set it to '';</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Just a thought -- I'll stop sharing
now.</FONT></DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=geeklog@langfamily.ca href="mailto:geeklog@langfamily.ca">Blaine
Lang</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A
title=geeklog-devtalk@lists.geeklog.net
href="mailto:geeklog-devtalk@lists.geeklog.net">geeklog-devtalk@lists.geeklog.net</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Sunday, February 29, 2004 1:19
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [geeklog-devtalk] Variable
best practices</DIV>
<DIV><BR></DIV>
<DIV><FONT face=Arial size=2>I've been wanting to address this issue for a
while and have come up with the following function.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>It will filter either GET, POST or both (as in my
need noted below - but look for POST first).</FONT></DIV>
<DIV><FONT face=Arial size=2>It will appy the data filter - default mode for
now.</FONT></DIV>
<DIV><FONT face=Arial size=2>It will also optionally create GLOBALS out of the
variables. This could be used to remove a dependany on
Register_globals.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Example use:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>$myvars =
array('op','profileid','memberid');<BR>getdata($myvars,true);</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>or </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>$formvars = array('profile_name','member_num',
'member_addr', 'member_city', 'member_phone');<BR>$formdata =
array();<BR>$formdata = getdata($formvars,'POST');</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><< code begin >></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>function
getdata($vars,$setglobal=false,$type='') {<BR> $return_data =
array();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> #setup common reference to SuperGlobals
depending which array is needed<BR> if ($type == "GET" OR $type ==
"POST") {<BR> if ($type=="GET") { $SG_Array=& $_GET;
}<BR> if ($type=="POST") { $SG_Array=& $_POST;
}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> # loop through SuperGlobal
data array and grab out data for allowed fields if found<BR>
foreach($vars as $key) {<BR> if
(array_key_exists($key,$SG_Array)) { $return_data[$key]=$SG_Array[$key];
}<BR> }</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> } else {<BR> foreach
($vars as $key) {<BR> if (array_key_exists($key,
$_POST)) { <BR> $return_data[$key] =
$_POST[$key];<BR> } elseif
(array_key_exists($key, $_GET)) {
<BR> $return_data[$key] =
$_GET[$key];<BR> }<BR>
}<BR> }</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> # loop through $vars array and
apply the filter<BR> foreach($vars as $value)
{<BR> $return_data[$value] = <FONT
face="Times New Roman"
size=3>COM_applyFilter</FONT>($return_data[$value]);<BR>
}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2> // Optionally set $GLOBALS or return the
array<BR> if ($setglobal) {<BR> # loop
through final data and define all the variables using the $GLOBALS
array<BR> foreach ($return_data as
$key=>$value) {<BR>
$GLOBALS[$key]=$value;<BR> }<BR> } else
{<BR> return $return_data;<BR>
}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=geeklog@langfamily.ca href="mailto:geeklog@langfamily.ca">Blaine
Lang</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A
title=geeklog-devtalk@lists.geeklog.net
href="mailto:geeklog-devtalk@lists.geeklog.net">geeklog-devtalk@lists.geeklog.net</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Sunday, February 29, 2004 10:19
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [geeklog-devtalk] Variable
best practices</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>As a practce, I try not to have any register_globals dependancies. I
will use the full $HTTP_POST_VARS and $HTTP_GET_VARS variable
names. I'd lole to use the other supper globals ($_REQUEST, $_POST
and $_GET) and are still dependant on php version 4.1 or greater.
Most hosting services should be running by now but it can not be assumed I
guess.</DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV>I'm filtering all expected POST and GET vars now in my new plugins and
there are still times it makes sense to use the same name in the POST and
GET. It may be passed in the URL or form so you have to check both but I
check the post first as I would use that first if I can post a hidden
variable.</DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Examples are:</FONT></DIV>
<DIV><FONT face=Arial size=2>using $op to indicate operation. I may be
triggered from a link, selectbox, image or button in the UI. I may also have
to pass it to another script.</FONT></DIV>
<DIV><FONT face=Arial size=2>using $page and $sort as part of the page
google like navigation (links) but you also need to retain this as hidden
fields in forms if you want to retain your page position.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I don't see the reason to use different names
with the get and post as this allows me more control. I only expect it one
way or the other and POST should override get.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Hense why I end of having all this extra code
at the top of scripts:</FONT></DIV>
<DIV>> if (isset($HTTP_POST_VARS['op']) )
{<BR>> $op =
clubApplyFilter($HTTP_POST_VARS['op']);<BR>> } elseif
(isset($HTTP_GET_VARS['op']) ) {<BR>> $op =
clubApplyFilter($HTTP_GET_VARS['op']);<BR>> } else
{<BR>> $op = '';<BR>> }</DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Is this how others would approach
this?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I was thinking if I am having to repeat this
practice and common code, others would as well. Extending my class object to
handle this would be an advantage.</FONT></DIV>
<DIV><FONT face=Arial size=2><FONT face="Times New Roman" size=3>$myfilter =
new COM_filter;<BR>$myfilter->_censor = true;<BR>$myfilter ->_jsfilter
= true;</FONT><BR></FONT><FONT face=Arial size=2>$op =
$myfilter->_setvar('op', 'text');</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Cheers,</FONT></DIV>
<DIV><FONT face=Arial size=2>Blaine</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial
size=2></FONT> </DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>