This is a very important point to understand, I tried (and
failed) to explain it.  I think Leif made it pretty
clear though, here's another :)

// $a can be anything when you call the function
function bar ($a) {
    print $a;
}

bar ('Hello World');
bar ($_POST['something']);

Regards,
Philip Olson


On Fri, 20 Dec 2002, Leif K-Brooks wrote:

> You don't need to import the request variables for that to work.  The 
> variable names in the function definition have no relationship to 
> variables outside of it.  Most likely, you're calling with something like:
> check_banlist($banlist,$p_email);
> but you could also call it with:
> check_banlist($variable_with_a_totally_different_name,$another_oddly_named_variable);
> or call it with
> check_banlist('some string','another string');
> or even call it with
> check_banlist($banlist,$_POST['email']);
> so importing the request variables is pointless.  What you call the 
> variables inside the function doesn't have anything to do with whether 
> there is a global variable with the same name!
> 
> Jamie wrote:
> 
> > Thanks for the vote of confidence.  I ended up getting it working with 
> > this:
> >
> > import_request_variables('p', 'p_');
> > function check_banlist($banlist, $p_email) {
> >
> > This is what I had been trying to accomplish but was writing it this way:
> >
> > function check_banlist($banlist, $_POST['email']) {
> >
> > Maybe you could also point me to the lesson that needs to be learned 
> > here.  Is it that it is an array?  or syntax?
> >
> > Thanks for the assistance!
> >
> > Jamie Sullivan
> >
> > Philip Olson wrote:
> >
> >> First, read this:
> >>
> >>   http://www.php.net/variables.external
> >>
> >> Second, assuming you have a PHP version equal to
> >> or greater than 4.1.0 and the method of the form
> >> is POST, you'd do something like this:
> >>
> >>   $banlist = array('[EMAIL PROTECTED]');
> >>   echo check_banlist($banlist, $_POST['email']);
> >>
> >> Your question sounds like you're wondering if the
> >> function definition should change, it doesn't.  You
> >> leave it as $email and use $email within the function.
> >> This is just how functions work, you pass in values.
> >> So:
> >>
> >>   function foo ($email) {
> >>       print $email;
> >>   }
> >>
> >>   foo($_POST['email']);
> >>
> >>   // Or as you used to do with register_globals
> >>   foo($email);
> >>
> >> Or you could always just do:
> >>
> >>   function bar () {
> >>       print $_POST['email'];
> >>   }
> >>
> >>   bar();
> >>
> >> This is why they are SUPERglobals, because this is
> >> what you would have done in the past (old school):
> >>
> >>   function baz () {
> >>       global $email, $HTTP_POST_VARS;
> >>
> >>       print $email;
> >>
> >>       print $HTTP_POST_VARS['email'];
> >>   }
> >>
> >> Also it's worth mentioning that $HTTP_POST_VARS has existed since PHP 
> >> 3, so just in case that might be important to you too.  It is not super.
> >>
> >> Now if you don't care if 'email' comes from GET, POST,
> >> or COOKIE ... you could use $_REQUEST['email'].  Or,
> >> import_request_variables() is another option.  For
> >> example:
> >>
> >>   import_request_variables('p', 'p_');
> >>
> >>   print $p_email;
> >>
> >> See the manual for details, and have fun!  It really
> >> isn't that complicated and you'll be yelling out
> >> Eureka! pretty soon now.
> >>
> >> Regards,
> >> Philip Olson
> >>
> >> P.s. Superglobals work with register_globals on or off.
> >>
> >>
> >> On Thu, 19 Dec 2002, Jamie wrote:
> >>
> >>
> >>> I am attempting to modify an old script to support the superglobal 
> >>> $_POST with register_globals=Off.  These register globals are 
> >>> definately challenging when you are new to php and every example 
> >>> shown anywhere uses the old method but I guess what doesn't kill you 
> >>> only makes you stronger.
> >>>
> >>> I am trying to convert this line, $email is coming from an html form 
> >>> so I would typically call it with $_POST['email'] but this doesn't 
> >>> work in this case and I thus far haven't been able to find anything 
> >>> that explains what I should be doing.
> >>>
> >>> function check_banlist($banlist, $email) {
> >>>
> >>> Any assistance is appreciated!  Thanks,
> >>>
> >>> Jamie
> >>>
> >>>
> >>> -- 
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>
> >>
> >
> >
> >
> 
> -- 
> The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
>to decrypt it will be prosecuted to the full extent of the law.
> 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to