$_GET problem with common.php

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
lutzz
Registered User
Posts: 6
Joined: Sun Oct 29, 2006 9:26 pm

$_GET problem with common.php

Post by lutzz »

I've previously made the PHPBB integration into my website work, so that they share the same database and go through the same session authentication (through inclusion of common.php). It worked fine on my own computer's server, but when I uploaded it online, for some reason, $_GET stopped working the moment the line

Code: Select all

include("forums/common.php");
was included.

If I used $foo = $_GET['foo']; and outputted it before the common.php was included, everything would work, but right after I included common.php, $foo would have no value, and I couldn't use that variable anymore.

I've tried all different names, none of the variable names conflict with the file, what's wrong?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52111
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Post by Brf »

common.php copies $_GET into $HTTP_GET_VARS
lutzz
Registered User
Posts: 6
Joined: Sun Oct 29, 2006 9:26 pm

Post by lutzz »

Brf wrote: common.php copies $_GET into $HTTP_GET_VARS
Tried replacing $_GET with $HTTP_GET_VARS: does nothing =\
User avatar
Brf
Support Team Member
Support Team Member
Posts: 52111
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Post by Brf »

Did you try:

Code: Select all

$foo = $HTTP_GET_VARS['foo']; 

You are using http://mypage.php?foo=bar ?
lutzz
Registered User
Posts: 6
Joined: Sun Oct 29, 2006 9:26 pm

Post by lutzz »

Brf wrote: Did you try:

Code: Select all

$foo = $HTTP_GET_VARS['foo']; 
?
Yeah, that's exactly what I tried, and it still nullified the variable, leaving it with no value.
lutzz
Registered User
Posts: 6
Joined: Sun Oct 29, 2006 9:26 pm

Post by lutzz »

Still haven't been able to figure it out.

I can still retrieve any $_GET from before common.php, but once I include common.php, all the $_GET s disappear.

This is different on different servers; it's the same common.php but for some reason it acts differently. $_GET still works, it just has different effects under the same common.php file...

any ideas?
Graham
Former Team Member
Posts: 8462
Joined: Tue Mar 19, 2002 7:11 pm
Location: UK
Contact:

Post by Graham »

Perhaps a sample of your code would be useful to post ;)

You should do assignments after you have included common.php - anything set before it is included that is not in a specified list will be unset (although the data is still there in the HTTP_GET_VARS and can be assigned afterwatrds)
"So Long, and Thanks for All the Fish"

phpBB Useful Links: Knowledge Base | Userguide | Forum Search | MOD Database | Styles Database
My Links: Blog!
lutzz
Registered User
Posts: 6
Joined: Sun Oct 29, 2006 9:26 pm

Post by lutzz »

Graham wrote: Perhaps a sample of your code would be useful to post ;)

You should do assignments after you have included common.php - anything set before it is included that is not in a specified list will be unset (although the data is still there in the HTTP_GET_VARS and can be assigned afterwatrds)

Code: Select all

<?
$page = $_GET['page'];
define('IN_PHPBB', true); 
$phpbb_root_path = 'forums/'; 

include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.php'); 

$userdata = session_pagestart($user_ip, PAGE_INDEX); 
init_userprefs($userdata); 
?>
After the include("common.php"); my $page is clear, it has no value.[/quote]
User avatar
Ptirhiik
Registered User
Posts: 7411
Joined: Mon Jan 06, 2003 10:36 pm
Contact:

Post by Ptirhiik »

You have register_globals on, therefore any unexpected var are unset by common.php. The best solution is to set your register_globals off (php.ini).
lutzz
Registered User
Posts: 6
Joined: Sun Oct 29, 2006 9:26 pm

Post by lutzz »

Ptirhiik wrote: You have register_globals on, therefore any unexpected var are unset by common.php. The best solution is to set your register_globals off (php.ini).
Any way to get around it without having direct server access?
User avatar
Ptirhiik
Registered User
Posts: 7411
Joined: Mon Jan 06, 2003 10:36 pm
Contact:

Post by Ptirhiik »

Don't use $_GET but $HTTP_GET_VARS (same for other super-globals), and don't declare any vars prior the inclusion of common.php except $phpbb_root_path & $phpEx (which is declared in extension.inc). On a side note, you can drop the inclusion of extension.inc by replacing it with this line:

Code: Select all

$phpEx = substr(strrchr(__FILE__, '.'), 1);
User avatar
igorw
Former Team Member
Posts: 8024
Joined: Fri Dec 16, 2005 12:23 pm
Location: {postrow.POSTER_FROM}
Name: Igor Wiedler

Post by igorw »

Ptirhiik wrote: On a side note, you can drop the inclusion of extension.inc by replacing it with this line


Where did he get that from? *cough* olympus *cough* :lol:
Igor Wiedler | area51 | GitHub | trashbin | Formerly known as evil less than three
User avatar
Ptirhiik
Registered User
Posts: 7411
Joined: Mon Jan 06, 2003 10:36 pm
Contact:

Post by Ptirhiik »

Not really: I was using this way prior looking at Olympus (found in the php doc samples I think). However, I haven't been surprised to see the same within Olympus.
arod-1
Registered User
Posts: 1327
Joined: Mon Sep 20, 2004 1:33 pm

Post by arod-1 »

actually, i think there is a very easy way around it:
don't call it $foo!
or, more precisely, don't use the same name for the $_GET parameter and the php variable:

$my_var = $_GET['my_var'] will be squashed by common.php
$some_other_var = $_GET['my_var'] will remain safe, as common.php will unset $my_var, but will leave $some_other_var alone.

warning: this is a conclusion based on reading the code. i didn't actually try it!
standard disclaimer:
backup your db and files before you do anything.
absolutely no guarantee.
if you do what i advise and it blows in your face, all you'll hear from me is: "ah... sorry, i guess"
Post Reply

Return to “[2.0.x] MOD Writers Discussion”