Hello All,

My old computer crashed. I installed XAMMP on my new computer. My old PHP files don't run. I learned that the reason is that register_globals feature has been deprecated and is now permanently Off by default. My old files were written in a 'register_globals=On' environment. I understand that one results is that the superglobals, such as $_POST[], no longer carry HTML form variables into the PHP area. I need to update the code of my old files to accomodate this change.

I reviewed prior threads related to the 'Undefined Index error' that is given when trying to use $_POST[] in PHP 5.3 and higher. But found only two over the past 5 or 6 weeks. One did not generate any replies, and the other generated only one reply that was incorrect.

In Internet searches, I have seen suggestions of using FILTER_INPUT() with functions called INPUT_GET or INPUT_POST. I have not been able to grasp how to use them to carry HTML form data to PHP variable for some type of processing.

How can I process form data without using the old superglobals? How can I update my old files with a minimum of re-writing?

Thanks in Advance.

Nathaniel

$_POST is available
a superglobal, it is not affected by the register_globals directive
perhaps the error is elsewhere in your code

$_POST[] works fine on php 5.3.x , global varibales are disabled from day I've learned PHP :P

Did you check to see if <input type="xxx" name="SOMEKEY"> matches up with $_POST['SOMEKEY']?

Hello All,

Thank you for responding to my question. I had to set it aside for a few weeks because oher things in life intervened. I am learning program part-time. This is not ideal becuase you really need to be immersed in it, but my current circumstances do not permit a heavy time committment.

I recently found a solution to my problem. My old computer had the php.ini file set to suppress error reporting. XAMMP has a default of setting for error reporting to include E_NOTICE. My code was wrong, or at least weaker than ideal, but PHP didn't report the weaknesses. I was using variables before verifying that they existed.

In XAMMP the weaknesses are being reported. As it is better practice to report errors, I needed to improve my code. I found two receommendations; one using isset() and the other using array_key_exists(). I chose the array method. So my prior code of:

$phpvariable = $_POST['htmlformvariable'];

is now:

$phpvariable = array_key_exists('htmlformvariable', $_POST) ? $_POST['htmlformvariable'] : NULL;

And I have no more notices.

I also discovered there is a lot of misinformation and misunderstanding in the cyberspace regarding PHP best practices. One must be very persistent and diligent in order to find what one needs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.