PHP not behaving properly

syncdot

macrumors newbie
Original poster
Feb 19, 2005
2
0
I'm not sure if there's a name to call this but I'll just explain my problem.

You know using the same PHP file, let's say "test.php", you can call for different parts of the code using the "?" and if there's more than one variables to specify, you can then add the "&". For instance, I wanna call this from the browser: "test.php?Variable1=Yes&Variable2=No". This seems to work when I put the PHP file in Window's Apache Server, but on OS X 10.3's Apache Server, it does not seem to read the syntax after "?", so it loaded the whole "test.php" file.

Is there any feature that I have to enable on Mac? Please help.
 

dornoforpyros

macrumors 68040
Oct 19, 2004
3,070
3
Calgary, AB
I realize I may not be of any help but when I was messing around with PHP I found it behaved differently on local host as appose to a live server. I ended up moving some of my tags to before my <html> declaration.

Once again i dunno if this is of any help
 

angelneo

macrumors 68000
Jun 13, 2004
1,541
0
afk
I have not installed php on Mac before.. but here's a suggestion. do a phpinfo() on the windows machine and another on the Mac machine. Try comparing them both, preferably comparing the server settings.
 

Mitthrawnuruodo

Moderator emeritus
Mar 10, 2004
13,805
174
Bergen, Norway
Have you remembered to include a
Code:
<?php
extract($HTTP_GET_VARS);
?>
on the top of your file, before trying to access $Variable1 and $Variable2...?

Edit: Also, I've had som trouble with variables given strings, like your ?Variable1=Yes, I found that I get much less hassle when using numbers, like ?Variable1=1 for 'yes' and 0 for 'no'...
 

brap

macrumors 68000
May 10, 2004
1,701
0
Nottingham
Mitthrawnuruodo said:
Have you remembered to include a
Code:
<?php
extract($HTTP_GET_VARS);
?>
on the top of your file, before trying to access $Variable1 and $Variable2...?
Or, you could just use:
Code:
<?
$myvar = $_GET["variablename"];
?>
Doesn't require the http_get_vars line - is the equivalent of ASP Request.Querystring command.
 

Mitthrawnuruodo

Moderator emeritus
Mar 10, 2004
13,805
174
Bergen, Norway
brap said:
Or, you could just use:
Code:
<?
$myvar = $_GET["variablename"];
?>
Doesn't require the http_get_vars line - is the equivalent of ASP Request.Querystring command.
Yes, but the extract($HTTP_GET_VARS); collects all variables and let you use them directly (a if (!isset($var)) might be needed sometimes, but still...)

I'm just a little lazy when coding php... :p :D
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
Mitthrawnuruodo said:
Have you remembered to include a
Code:
<?php
extract($HTTP_GET_VARS);
?>
on the top of your file, before trying to access $Variable1 and $Variable2...?

Yes: on OSX register_globals is set to off by default for security reasons (to avoid varibale injection). So each variable that is passed through to your script (by GET, POST, SESSION, etc) needs to be extracted first from the appropiate array ($_GET, $_POST, $_SESSION) with the variable name as the array key ($_GET['var1'], $_GET['var2'], etc). There's also an array that contains all the variables that the server uses, but I can't remember it's name.


Though Mitthrawnuruodo's way will work fine, it kind of negates the security advantages of not registering globals. The best way is to *only* extract the variables you need, and even verify their format if possible (this is true for variables supplied by the user). This sound a bit of a pain but there is an easyish way of doing it:

Code:
# list of vars needed to be extracted
$vars = array ('var1', 'var2', 'var3');


#extract the variables
foreach ($vars as $var)
{

    $$var = $_GET[$var];

}
 

syncdot

macrumors newbie
Original poster
Feb 19, 2005
2
0
THANK YOU THANK YOU

Mitthrawnuruodo said:
Have you remembered to include a
Code:
<?php
extract($HTTP_GET_VARS);
?>
on the top of your file, before trying to access $Variable1 and $Variable2...?

Edit: Also, I've had som trouble with variables given strings, like your ?Variable1=Yes, I found that I get much less hassle when using numbers, like ?Variable1=1 for 'yes' and 0 for 'no'...
Thank you thank you! It's because I didn't include the extract($HTTP_GET_VARS). But why does it still work in Windows?

Anyhow, I can now at last (Finally!) code and preview websites on OS X instead of going to Virtual PC (which is very terribly bloody slow).

Thanks again guys! :D
 

whocares

macrumors 65816
Oct 9, 2002
1,496
0
:noitаɔo˩
syncdot said:
Thank you thank you! It's because I didn't include the extract($HTTP_GET_VARS). But why does it still work in Windows?

Because it's redundunt (sp?) with register_globals being on on the Windows machine ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.