Gettting values from URL in PHP 5.4 [message #179908] |
Tue, 18 December 2012 17:50 |
Tim Rude
Messages: 2 Registered: December 2012
Karma: 0
|
Junior Member |
|
|
Sorry if this is a dumb question. I'm a PHP novice.
We have been using PHP 4 on a page in our website to pre-populate some text
boxes on a form. The text is passed as part of the URL.
Here's a sample url showing how the data is passed:
http://www.samplesite.com/mypage.php?name=Sample+Name&addr=123+Main+Str eet&city=Sometown%2C+AL+12354
Here's the code I use on the page to populate the form boxes:
<input type="text" name="on0" maxlength="40" value="<?php echo $name; ?>">
<input type="text" name="os0" maxlength="40" value="<?php echo $addr; ?>">
<input type="text" name="on1" maxlength="40" value="<?php echo $city; ?>">
With PHP 4, it works perfectly.
Now our hosting provider is updating from PHP 4 to PHP 5.4. But with PHP
5.4, none of the form boxes get populated. There's no error message or
anything, it just simply leaves the form boxes blank as if nothing was
passed via the URL.
What do I need to do to get it working with PHP 5.4?
Tim Rude
|
|
|
Re: Gettting values from URL in PHP 5.4 [message #179909 is a reply to message #179908] |
Tue, 18 December 2012 17:55 |
Salvatore
Messages: 38 Registered: September 2012
Karma: 0
|
Member |
|
|
On 2012-12-18, Tim Rude <timrude(dot)nospam(at)nospam(dot)hotmail(dot)com> wrote:
> Here's the code I use on the page to populate the form boxes:
>
> <input type="text" name="on0" maxlength="40" value="<?php echo $name; ?>">
> <input type="text" name="os0" maxlength="40" value="<?php echo $addr; ?>">
> <input type="text" name="on1" maxlength="40" value="<?php echo $city; ?>">
>
> With PHP 4, it works perfectly.
If you wrote your code like that throughout your site, you have a lot of
editing to do. The correct way to reference a request variable is
$_REQUEST['key']. So replace "$name" with "$_REQUEST['name'] and repeat
that step for the other values.
--
Blah blah bleh...
GCS/CM d(-)@>-- s+:- !a C++$ UBL++++$ L+$ W+++$ w M++ Y++ b++
|
|
|
|
Re: Gettting values from URL in PHP 5.4 [message #179911 is a reply to message #179910] |
Tue, 18 December 2012 19:44 |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 12/18/2012 2:12 PM, Christoph Becker wrote:
> Tim Rude wrote:
>> With PHP 4, it works perfectly.
>
> The working of the code is actually not directly related to the PHP
> version, but to the PHP ini setting "register_globals"
> (<http://php.net/manual/en/security.globals.php>). This setting has
> been finally removed from PHP 5.4.
>
> How to fix your existing code has already been explained by Salvatore.
> I would prefer using $_GET, $_POST or $_COOKIE instead of $_REQUEST.
>
I agree. Use the proper array - $_GET, $_POST or $_COOKIE.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: Gettting values from URL in PHP 5.4 [message #179912 is a reply to message #179911] |
Tue, 18 December 2012 20:02 |
Tim Rude
Messages: 2 Registered: December 2012
Karma: 0
|
Junior Member |
|
|
"Jerry Stuckle" <jstucklex(at)attglobal(dot)net> wrote in message
news:kaqh46$pck$1(at)dont-email(dot)me...
> On 12/18/2012 2:12 PM, Christoph Becker wrote:
>> Tim Rude wrote:
>>> With PHP 4, it works perfectly.
>>
>> The working of the code is actually not directly related to the PHP
>> version, but to the PHP ini setting "register_globals"
>> (<http://php.net/manual/en/security.globals.php>). This setting has
>> been finally removed from PHP 5.4.
>>
>> How to fix your existing code has already been explained by Salvatore.
>> I would prefer using $_GET, $_POST or $_COOKIE instead of $_REQUEST.
>>
>
> I agree. Use the proper array - $_GET, $_POST or $_COOKIE.
>
Thank you all. Fortunately I only have this code in 6 spots on one page, so
it's an easy fix to add the $_GET.
Much obliged. :)
Tim Rude
|
|
|