Manual of PHP

 
 
 

Web map

 
rim   rim
arrowReady frontarrow of Codes PHParrow to Spend the variables SESSION, POST AND GET to normal variables in PHP

 

To spend the variables SESSION, POST AND GET to normal variables in PHP To print E-mail
How to do that a few global variables as it is GET, SESSION and POST talk each other like normal variables in PHP.

Does it do a pair of weeks it was entrusted to me to migrate a place (developed in php) of servant, the topic was going relatively in peace until I realized of a problem appellant in this type of situations, the ancient servant had the global variables in On and did the new one them have in Off... appellant not?

Is the truth that I did not want to complicate the life like other times, and I realized something that might save a pair of working time, all the php were doing an include to a file php, appellant also not?
Like that is that I started thinking about a piece of code that should me to take these 3 types of variables (SESSION, POST AND GET) and it will leave them to me like normal variables, if they it do not realize well the exercise it is more or less the following one:

Let's suppose that the variable comes from a form route POST, the code was saying something like that...

<?

if ($variable = "a little")
{
   I begin "this variable does some thing";
}

?>


Namely he was lacking this instruction before the if

<? php

$variable = $_POST ["variable"];//he was lacking this instruction before the if

if ($variable = "a little")
{
   I begin "this variable does some thing";
}

?>


It had 2 options, or was starting looking for ALL these situations and one was arranging them to one, or it was placing a code piece in file to which all the rest were making him an include who was correcting this proper "error" of those that we are to be employed with the "servants at production", or, with the global variables in On.

Very well, after many blending me I found the solution, and here I show it to all uds.

<?

if ($_POST)
{
   $keys_post = array_keys ($_POST);
   foreach ($keys_post grasp $key_post)
     {
      $$key_post = $_POST [$key_post];
      error_log ("variable $key_post comes from $ _POST");
     }
}

if ($_GET)
{
   $keys_get = array_keys ($_GET);
   foreach ($keys_get grasp $key_get)
     {
        $$key_get = $_GET [$key_get];
        error_log ("variable $key_get comes from $ _GET");
     }
}

if ($_SESSION)
{
   $keys_sesion = array_keys ($_SESSION);
   foreach ($keys_sesion grasp $key_sesion)
     {
       $$key_sesion = $_SESSION [$key_sesion];
       error_log ("variable $key_sesion comes from $ _SESSION");
     }
}

?>


There are basically 3 if that do the same, they take the keys of the arrangement in question (SESSION, POST or GET) and generate a "variable variable", I believe that there is an article in desarrolloweb that speaks about this topic, and this does the whole magic, error_log was an implementation to see that variables were dealing (if you do not have access to the servant you can extract it without problems).

For someone who likes the functions he can keep it also like function and call it when he needs it. Or also to iterate the process with 3 variables in question not to have to do 3 if, or spend any arrangement to him so that it does the same process... anyway, the this idea, only I hope to have contributed in something to the saving of time of some of you.

Juan Edgardo Jorquera Uribe
http://www.chile.com/

 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

used cars , Incentive Travel Poland , GlobeSpot.Net Web Directory , Holzhäuser , phone card colombia , Panasonic , waagen