Forums | MacLife
You are not logged in.
#1 2003-01-17 12:31 pm
Variables on Local Webserver
I installed PHP and MySQL on my Mac (OS 10.2.3) using the great instructions on entropy.ch, and all works fine except...
When I try to pass any variables (through a form or a plain old link) to another page, they are all blank. The code is fine, it works perfectly on my Linux server. I just want to be able to test php pages frequently as I work on them. Uploading for each trial run is getting old.
What's up with Apache on OSX? Is there a fix for this, or can I just change something in the config?
Even if I type it into the browser (http://127.0.0.1/index.011.php?ID=9&page=nine) the vars are all blank on the page.
PLZ help!
Offline
#2 2003-01-17 2:02 pm
- lostghost
- Member
- From: Chicago
- Registered: 2001-07-08
- Posts: 496
Re: Variables on Local Webserver
Depending upon your PHP configuration, the way that you are able to reference GET and POST variables will vary.
If you have recently installed PHP from www.entropy.ch, then you have installed version 4.2.3. One of the primary changes between 4.2.3 and earlier versions (like the version on your server) is that 4.2.3 no longer defaults to register globals.
This means that variables pass via GET and POST methods cannot simply be referenced by their name.
The preferred method for referencing passed variables for PHP versions 4.1.0 and later is to use the $_GET, $_POST, or $_REQUEST superglobal arrays.
If you requested a page with:
Code:
http://someurl/page.php?foo=bar
You could access the varable "foo" with:
Code:
<?php echo $_REQUEST["foo"]; ?>
http://www.php.net/manual/en/language.variables.external.php
Offline
#3 2003-01-17 8:47 pm
Re: Variables on Local Webserver
Thanks for the info!
The $_REQUEST thing works and is a nice quick fix, but I would like to get my Apache configured so I can use variables normally.
I set 'AllowOverride All' in my httpd.conf and added a .htaccess file containing 'php_flag register_globals on' in my Sites folder. Still no luck.
How can I turn register globals back on? I'm behind a firewall, so I'm not concerned with security on my local machine.
Offline
#4 2003-01-17 10:38 pm
Re: Variables on Local Webserver
I found a better workaround. I put this code in the top of my page:
Code:
import_request_variables ("gpc");
It does all the dirtywork of $_REQUEST, etc. in one fell swoop, without changing my existing code or messy config files.
Thanks php_dot_net! ..and lostghost, of course!
Offline
#5 2003-01-18 2:35 pm
- lostghost
- Member
- From: Chicago
- Registered: 2001-07-08
- Posts: 496
Re: Variables on Local Webserver
You can configure PHP to register globals but there are very good reasons to leave it off and develop without.
1) All new versions of PHP will default to register globals off, and most hosting providers will leave it off. This means that if you develop a site that assumes register globals is on, then when the server is updated, you will have to update your code. It makes more sense to develop it now in a way that will not need to be updated.
2) Register globals presents a serious security hole, that a firewall does not protect. This is from the PHP.net website, security section:
One feature of PHP that can be used to enhance security is configuring PHP with register_globals = off. By turning off the ability for any user-submitted variable to be injected into PHP code, you can reduce the amount of variable poisoning a potential attacker may inflict. They will have to take the additional time to forge submissions, and your internal variables are effectively isolated from user submitted data.
While it does slightly increase the amount of effort required to work with PHP, it has been argued that the benefits far outweigh the effort.
The import_request_variable() function will accomplish the samething as register globals and if used correctly, is far more secure than register globals, but you do still have the possibility of variable poisoning.
Offline
#7 2003-01-20 12:03 am
Re: Variables on Local Webserver
I see. That is really nice to know.
I have been using eregi to make sure referer matches my domain before it does anything with passed vars.
That won't help you with the hole, as the data will still be passed from your page.
For example, you have a page:
login.php
Suppose that page uses in it a variable called $auth_ok which is unset and some sort of routine is used to verify a user and switches $auth_ok to true allowing access. If someone were to simply add:
login.php?auth_ok=1
That would allow access. And the referer is still your site. Not a likely example, but an illustrative one.
In fact any variable in your page could be set or tweaked (at the start) by simply adding it to the url string. Turning that off seperates your internal variables from passed ones. It simply means that no variable can be inserted by the user without you taking action.
Is it a huge security risk? No, not a huge one. But it depends on your code (or someone elses if you use something pre built.) A clean coder wouldn't leave holes like that. But a clean coder would also take advantage of barriers like that. Malicious idiots are creative, I rather plug a small potential hole than clean up the mess later.
Offline
#8 2003-01-20 8:19 am
Re: Variables on Local Webserver
I've tried to hack it myself to be sure, and didn't have any success (and I know all the var names). My 'security' portion of the script checks for referrer every time, so 0/1 will be reset even if they figured out the correct variable name and typed it into the address bar.
...but what's the alternative to opening up a security hole? I need to move data from page to page. I guess I could make import_request_variables conditional. ...or do you suggest just using $_REQUEST, etc. only on the variables I need?
(TIA for all this great info, BTW)
Offline
#9 2003-01-20 9:46 pm
Re: Variables on Local Webserver
I've tried to hack it myself to be sure, and didn't have any success (and I know all the var names). My 'security' portion of the script checks for referrer every time, so 0/1 will be reset even if they figured out the correct variable name and typed it into the address bar.
Falsifing a referrer is easy enough to do. That is the point of having the request globals off, it puts control into the hands of the script not the client side.
...but what's the alternative to opening up a security hole? I need to move data from page to page. I guess I could make import_request_variables conditional. ...or do you suggest just using $_REQUEST, etc. only on the variables I need?
$_COOKIE['var_name'], $_POST['var_name'], $_GET['var_name'], etc...
it the safest way. But it using the import_request_variables with prefix it safe as well because you are isolating request vars.
So:
import_request_variables("gpc", "incoming_");
login.php?user=me
becomes:
$incoming_user in the script.
But really, careful coding is the best security. Out of habit, I always set every variable I use first, and scrub all user input. So the global setting of varibles won't affect my scripts, but it is always good to have multiple levels of security.
Offline

