|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Passing variables into functions and classes
Hi all,
Just a quick question. How do you pass a variable from a form into a function or class ? That is with register globals off and using something like $_POST['myVariable']. I'm new to all this stuff so please kind. Thanks in advance, Niall |
|
#2
|
|||
|
|||
|
Yes... with globals set to off, use this:
For post form method: $_POST['var_name']; For get form method: $_GET['var_name']; Or you can use a PHP special function that creates the variables for you, use this: @import_request_variables("GP"); The @ symbol is to omit errors... The G and P means: GET and POST. Using this will make any form variable avaible at your script, even if globals are set to off. You can even use the letter C too, that is for Cookies. And don't forget, that if you use this, the variable name at your script will be the same name as the form field name. In example: if a form field is named: "txtZip" then you'll have a variable in your script named: $txtZip
__________________
Regards, Ramiro Varandas Jr. |
|
#3
|
|||
|
|||
|
Thanks for your reply Ramiro.
Sorry it took me so long to get back to you. all the best, Niall |
|
#4
|
|||
|
|||
|
Quote:
Doesn't that just defeat the purpose of globals being off? Correct me if I'm wrong...
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#5
|
|||
|
|||
|
Not really, no
r_g being off is to reduce the risks of variable poisioning - import_request_variables simply takes the GPC superglobals and effectively performs extract() on them all. There's no risk of variable poisoning this way.But I'd still say stick with $_*. |
|
#6
|
|||
|
|||
|
Okay.... I wasn't sure what the main difference was. But as you said, I too, would rather stick with the superglobals!
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Passing variables into functions and classes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|