Web Hosting Talk







View Full Version : Php5 $_GET and $_POST


Luka
12-13-2007, 09:16 AM
Hi,
I have a script which begins with assigning values to $_POST and $_GET is they are not set:
if ( !isset($_POST['checkout_choice']) && !isset($_GET['choice']) )
{
$_POST['checkout_choice'] = 3;
$_GET['choice'] = 3;
}

It used to work fine on php4 shared server, but when I move to virtual server with php5 installed it wount work, its just not loading page like it will never execute.Can anyone please help me to solve this?

Steve_Arm
12-13-2007, 10:30 AM
I don't think the problem lies on this code.

delta1066
12-13-2007, 10:36 AM
I think you are approaching it from the wrong direction - You are trying to set the $_GET and $_POST variables - Thats something which is supposed to be passed to the script. While it might of worked in v4, I wouldn't recommend doing it like that at all.

What about something like:
if ( !isset($_POST['checkout_choice']))
{
$checkout_choice = 3;
}
else
{
$checkout_choice = $_POST['checkout_choice'];
}

Surely it makes sense to assign to local variables huh? - Otherwise if you don't your going to go to what i call 'dependancy hell'. You cannot rely upon php not to change in each version - you can only rely upon yourself to save you from it!

orbitz
12-13-2007, 03:07 PM
oops. I messed up.

TonyB
12-13-2007, 04:14 PM
I'm wondering if it's throwing an error and you have display_errors off?

Usually PHP throws errors unless it actually crashes due to some weird code.

Luka
12-13-2007, 05:08 PM
It dont shows any error, and display_errors is set to ON

alexky
12-13-2007, 05:13 PM
take display_errors off, and check again

TonyB
12-14-2007, 04:12 PM
It dont shows any error, and display_errors is set to ON


To confirm this make an obvious syntax error. See if it produces any errors then.

Luka
12-14-2007, 04:47 PM
I have tried to make syntax error, and I get error message for it.....

delta1066
12-14-2007, 04:48 PM
Did you read my post earlier?

phporaclehosting
12-17-2007, 09:10 AM
there is nothing php4 or php5 specific in this your problem lies else where

Luka
12-17-2007, 09:27 AM
Hi, guys. I have solved this problem by setting values separately like this
if ( !isset($_POST['checkout_choice']) ) $_POST['checkout_choice'] = 3;

if ( !isset($_GET['choice']) ) $_GET['choice'] = 3;
Apparentaly when one variable isn't set it is reseting other as well.Now I have another problem.One class function has to use one of these vars ($_GET[choice]) , so I do "global $_GET;" in that function but it seems that its not working , $_GET[choice] is empty.As I wrote before, this was working on php4.What might be a problem here?

phporaclehosting
12-17-2007, 09:37 AM
global vars are bad, your code probably needs a re write, to make it php 5 nice, better putting your gets and posts into local vars and passing them via method arguments to your classes

delta1066
12-17-2007, 10:32 AM
Sounds like what i said too. Not that he took any notice "because it worked in php4"..

Luka, how many times must i repeat myself? - You can not rely on php to be the same in every version. You can only follow general good coding practice within the language to save you from dependancy problems.

Luka
12-17-2007, 10:42 AM
I uderstand, I gues I will have to re-do this script from begining.

delta1066
12-17-2007, 11:02 AM
You don't need to re-do the script from the beginning. Just modify it to make use of local variables in a similar way to what I showed you above.

If you had read my first post properly in the first place i probably wouldn't be telling you again!

Note that most editors have a "Replace" option in their edit menu. You might find that useful ;)

Saeven
12-19-2007, 04:05 AM
Just as friendly note, PHP5 adds $_REQUEST instead of $_GET and $_POST. Makes life much easier :)

delta1066
12-19-2007, 05:51 AM
So I would assume that $_REQUEST grabs the variable no matter which method was used?

Sounds cool...

bigfan
12-19-2007, 10:33 AM
No assuming necessary; $_REQUEST is a documented predefined variable (http://www.php.net/manual/en/language.variables.predefined.php). The documentation says, in part:Variables provided to the script via the GET, POST, and COOKIE input mechanisms, and which therefore cannot be trusted.