Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP4 > PHP5

Status
Not open for further replies.

DaveC426913

Programmer
Jul 28, 2003
274
CA
I'm tasked with upgrading an app from PHP4 to PHP5.

Is there a diff in how they read the querystring?

In PHP5, I'm using $_GET[], but the code for PHP4 does not have this, it seems to access the variables directly.

URL:
select_date.php?fm=eventForm&fld=event_date


PHP4 code in select_date.php:

<script>
function oldValue(){
var rawDate = window.opener.document.forms['<?= $fm ?>'].<?= $fld ?>.value;
}
</script>
<body onLoad="JavaScript:eek:ldValue()">

In PHP5 this code does not work. $fm and $fld are undefined - unless I add this:

$fm = $_GET['fm'];
$fld = $_GET['fld'];

Question is: How does the original code manage to work?
 
Because I'm fairly new to PHP5, let alone PHP4, I'm having a tough time understanding how that reference helps answer my question.

I can see that it is related, in that variables *can* come from the querystring. Does that mean that the variables in my code really are being pulled directly from the querystring? I guess so, yes.

I suppose that's consistent. The first thing I had to do in my conversion was to convert global variables
from form: $foo
to form: $GLOBALS['foo']
This new thing is sort of the same.



So, all I have to do is add a bunch of
$_GET[''] or $_POST['']
into my app, wheverever a value is being called from the querystring.

Unfortunately, there's no way of knowing which variables are pulled from the querystring without threading through the entire code. Also, I don't know whether it's a POST or a GET.

This app is pretty complex, using multiple classes and includes - several dozen interdependent files in all.
 
...Also, I don't know whether it's a POST or a GET..."

I suppose there would be no harm in converting all form submissions from POST to GET. Then I can always use $_GET[].
 
If register_globals is set to "off", PHP makes values available on in $_GET and $_POST. For example, the value of a form input named "foo" from a GET-method form will be found only in $_GET['foo'].

If register_globals is set to "on", not only will the value be available in $_GET, it will also be available as simply $foo.

If the code referencing $foo works on the old server but not the new, my first guess is that your old server has register_globals set to "on" and the new one to "off".

Having register_globals set to "on" has grave security risks, so the developers of PHP changed the default value of register_globals to "off" beginning with PHP 4.2.0.


What you are seeing is a side-effect of programming in a way that is dependent on register_globals being set to "on" -- you don't know from where your values are coming. If your code references elements of $_GET, it's pretty obvious.

I strongly recommend that if you are going to use one method (either "POST" or "GET"), that you use POST. There are limits, for example, to the amount of data that can be transmitted on a URL (which is how GET-method values are transmitted).



Want the best answers? Ask the best questions! TANSTAAFL!
 
IF All form submissions use Method POST, then just use the $_POST global,
or if you trully don't want to mess around with wether they are GEt or POST you can also use $_REQUEST which will contain both $_POST and $_GET values.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I would use POST because it hides the data, but let me ask a question about that:

POST only works on form submission data correct? for example: I can't use a redirect like this:

location = "foo.php?bar=1"

and expect to use $_POST to retrieve bar w/in page foo.php can I?

There are times when it's a huge pain to create a whole form just to pass a few pieces of data.
 
DaveC said:
I can't use a redirect like this:

location = "foo.php?bar=1"

Correct. That is a GET method. its equivalent to saying
Code:
<form action="foo.php" method=[red]GET[/red]>
<input type=hidden name=bar value=1>
...
</form>



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
vacunita:
If you're going to use $_REQUEST, you might as well simply turn register_globals on again. Using $_REQUEST opens the same variable-poisoning door.


DaveC426913:
No, you cannot sent POST-method data through a URL. That, by definition, is what GET-method data is.

If you need to redirect your users through the site yet still maintain data between pages, it sounds to me like you need to use session variables:


Want the best answers? Ask the best questions! TANSTAAFL!
 
'If the code referencing $foo works on the old server but not the new, my first guess is that your old server has register_globals set to "on" and the new one to "off"'.

Great! This will go a long way towards getting the app working. I'll flip the switch to ON, and do my install/repair. Once I've satisfied myself the app is working, I'll flip the switch OFF, and know that the only problems are with these variables.

Thanks!

In what file will I find this switch?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top