Page 1 of 1

Superglobals and Variables in URLs?

Posted: Sun Feb 10, 2008 12:29 pm
by olimess
Hi,

I'm new to this forum and hope that a few people (smarter then me) can help me out!

I recently was forced to switch hosting companies because my previous hosting company literally went out of business. Anyone with OnSmart better jump ship quick!

Anyways, the majority of the website transferred over to my new host with out a problem. There is one section though that isn't working properly. This section basically uses a flash file (.swf) to have the user make certain selections and to submit them. These selection are passed to another page using the following, very fimiliar, URL format.

http://www.mywebsite.com/loader.php?fil ... =thisvalue

Now, with my old hosting company, I didn't have to explicitly load each variable using the $_GET statement from with in loader.php. The variables embedded in the URL would automatically be recognized and could be used through out my loader.php script. This made it easy since there are literally 100s of variables that could potentially be passed from the flash file.


With my new hosting company, the variables embedded in the URL are not automatically recognzed with the loader.php page. Instead I have to spedifically load each variable using:

$filename = $_GET["filename"];
$subfilename = $_GET["subfilename"];
$anothervariable = $_GET["anothervariable"];

Simple enough, but with hundreds of variables and with several different pages and sections that potentially are affected (loader.php is not the only page in which variables are passed to and not explicitly loaded) this small problem has now turned into a huge problem for me.

My old hosting company used PHP version 4.3 I believe on an Appache/Linux server. My new hosting company uses PHP version 5.2.5 on an Appache/Linux server.


So my question is, can PHP on my new server be setup to work like the old ... is there a setting for this? I've been searching and can't definitely find one ... track_vars?? If this can't be done, is there someway that I can parse the URL and pull out each variable with out explicitly loading each variable using $_GET? Hope that makes sense.

If anyone could help me with this I would be EXTREMELY grateful!


Thanks,
Olimess

Re: Superglobals and Variables in URLs?

Posted: Sun Feb 10, 2008 12:54 pm
by Christopher
Look in the PHP manual for the register_globals configuration setting. You can set it "on" in scripts, in .htaccess files in directories, or in the php.ini file.

The register_globals setting is no longer set to "on" because of security risks. It will be removed completely in PHP6.

Re: Superglobals and Variables in URLs?

Posted: Sun Feb 10, 2008 1:04 pm
by olimess
Actually I just read that too. Never realized that register_globals was related to my situation. How do I go about setting registered globals to on in the loader.php page?


Thanks for the help by the way!


Also, could the same be done without setting register_globals to on. I know this is strongly discouraged. Could it be done by parsing the URL somehow?

THanks.

Re: Superglobals and Variables in URLs?

Posted: Sun Feb 10, 2008 2:24 pm
by JAM
Here's an example of doing this using .htaccess as using ini_set() (another 'php' way/function) wont work good enough.

Code: Select all

php_flag register_globals on
You could also make something as;

Code: Select all

    foreach($_GET AS $key => $value) {
        ${$key} = $value;
    }
But, you should take the time and change it all together... :banghead:

Re: Superglobals and Variables in URLs?

Posted: Sun Feb 10, 2008 2:28 pm
by Christopher
As JAM notes, you could also include this script at the top each file or use the auto_prepend feature:

Code: Select all

    foreach($_REQUEST as $key => $value) {
        ${$key} = $value;
    }

Re: Superglobals and Variables in URLs?

Posted: Sun Feb 10, 2008 3:32 pm
by lucia
what about doing an extract of the $_POST or $_GET arrays:
extract($_POST)
"This function is used to import variables from an array into the current symbol table. It takes an associative array var_array and treats keys as variable names and values as variable values"
so, after the extract, doing $x = $_GET['name'] is the same as $x = $name