|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Enthusiast
![]() Join Date: Dec 2001
Location: London
Posts: 30
|
register globals off and legacy code
OK
So now php 4.1 and above has the register globals defaulted to off. However as i am supporting legacy code then i need to switch them on just for that code? I'm going to leave the default settings as register gobals = off in the php.ini file i believe it is soething to do with $_server(register_globals) can anyone shed some light on this ? |
|
|
|
|
|
#2 |
|
SitePoint Wizard
![]() ![]() Join Date: Nov 2000
Location: Switzerland
Posts: 2,898
|
You've got a couple of choices.
One is to use a .htaccess file in the application directory containing; Code:
<IfModule mod_php4.c>
php_flag register_globals on
</IfModule>
PHP Code:
PHP Code:
|
|
|
|
|
|
#3 |
|
SitePoint Enthusiast
![]() Join Date: Dec 2001
Location: London
Posts: 30
|
register globals off and legacy code
Thanks,
however that means that i have to go through the code and change all variables to have the $_GET / $_POST that is going to be a real pain :-). I was hpoing there was a php option function that would allow me to switch on register globals. Oh well never mind thanks again |
|
|
|
|
|
#4 |
|
SitePoint Wizard
![]() ![]() Join Date: Nov 2000
Location: Switzerland
Posts: 2,898
|
No no - it doesn't.
If you include that code above, you can keep register_globals off, and you won't need to change any code. For example, if you have a link like; http://www.yourdomain.com/index.php?view=news And your code was like; PHP Code:
That would correspond to the $_GET variable, i.e. $_GET['view'] = "news". Now that code above "recreates" this variable to make it look like globals are on; PHP Code:
The first section of code above is for people using versions of PHP below 4.1, which don't regonised the new variables like $_GET - that's just for backward compatibility. Why not try it on your code with register globals off - it should work. |
|
|
|
|
|
#5 |
|
SitePoint Enthusiast
![]() Join Date: Dec 2001
Location: London
Posts: 30
|
legacy code
Harry
Yeah i get it now Thanks for your help :-D |
|
|
|
|
|
#6 |
|
SitePoint Enthusiast
![]() Join Date: Dec 2001
Location: London
Posts: 30
|
one more question
Ok then how do you pass the $_GET values to function
i have the following code function show_top_menu($_GET['this_section_id'],$_GET['side_section_id'],$site_url) but it throws this error Parse error: parse error, unexpected '[', expecting ')' in g:\web_server\htdocs\mp\scripts\mcintosh.php on line 119 and i'm calling it from the following code <? show_side_menu($_GET['this_section_id'],$_GET['sub_section_id'],$site_url); ?> any ideas? |
|
|
|
|
|
#7 |
|
SitePoint Wizard
![]() ![]() Join Date: Nov 2000
Location: Switzerland
Posts: 2,898
|
Errr - are you sure you've got the right function call?
The function you've put there is "show_top_menu" but you're calling "show_side_menu". Anyway - what's on line 119? |
|
|
|
|
|
#8 |
|
Super Ninja Monkey
![]() ![]() ![]() ![]() ![]() Join Date: Dec 2001
Location: Sioux City, Iowa
Posts: 693
|
instead of that big chuck of code Harry gave for extracting the variables you could use extract($_GET) and so on for all the superglobals.
__________________
Travis Watkins - Hyperactive Coder My Blog: Realist Anew Projects: Alacarte - Gnome Menu Editor |
|
|
|
|
|
#9 |
|
SitePoint Wizard
![]() Join Date: Sep 2001
Location: Singapore
Posts: 5,312
|
yeah exactly harry... i was looking through that long piece of code and thinking the exact same thing Trav said...
![]() and yes code above line 119 would be good, together with an indication of what's line 119 ![]() |
|
|
|
|
|
#10 |
|
SitePoint Wizard
![]() ![]() Join Date: Nov 2000
Location: Switzerland
Posts: 2,898
|
Don't know the extract function that well. When it creates the variables from the array, does it maintain the reference to the origional data?
Doing this; PHP Code:
|
|
|
|
|
|
#11 |
|
SitePoint Wizard
![]() ![]() Join Date: Nov 2000
Location: Switzerland
Posts: 2,898
|
Actually - now I look at it, the code I posted doesn't preserve the reference.
Guess it would need to be like; PHP Code:
|
|
|
|
|
|
#12 | |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: May 2002
Location: Southern California
Posts: 408
|
Quote:
|
|
|
|
|
|
|
#13 |
|
Making a better wheel
![]() Join Date: Jul 2001
Location: Missouri
Posts: 3,425
|
just put it in the "highest up" directory. it will affect all subdirectories.
![]()
__________________
- Matt ![]() Dr.BB - Highly optimized to be 2-3x faster than the "Big 3." ![]() "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 09:24.














Linear Mode
