Page doesn't work with register_globals=on

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fredmcfly2
Forum Newbie
Posts: 9
Joined: Tue Sep 27, 2005 2:41 pm

Page doesn't work with register_globals=on

Post by fredmcfly2 »

I have develped a webpage on a test server where register_globals=off, but now I am trying to move the page over to a production server where register_globals=on (sadly it's not an option to turn globals off on the production server). With register_globals=on the page will not load at all. I am at a loss as to why the page will load when globals are off and won't load when globals are on. I have done a ton of searching but can't find a solution. Can someone please help me?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

any errors? (make sure to check the error logs)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Page doesn't work with register_globals=on

Post by Roja »

fredmcfly2 wrote:I have develped a webpage on a test server where register_globals=off, but now I am trying to move the page over to a production server where register_globals=on (sadly it's not an option to turn globals off on the production server).
You can turn them off in htaccess files or in the script itself. It is absolutely an option to turn it off, and on a production server, you definitely should: Even if the server itself won't.
fredmcfly2 wrote: With register_globals=on the page will not load at all. I am at a loss as to why the page will load when globals are off and won't load when globals are on. I have done a ton of searching but can't find a solution. Can someone please help me?
With no code, we have no idea what could be causing the problem. The best analogy is going to a doctor and saying "I'm sick. Don't do a physical, and don't ask what my history is, but make me better."

Yes, we can help, and yes, there are things that can happen in that situation that could cause your page to not function properly. Can't be more specific until you are. ;)
fredmcfly2
Forum Newbie
Posts: 9
Joined: Tue Sep 27, 2005 2:41 pm

Post by fredmcfly2 »

Checked error logs, there are no errors. The browser says, "Fatal error: Maximum execution time of 30 seconds exceeded in C:\..\file.php on line 45" Here is what line 45 says:

#If we dont know the right date then make it up
if (!isset($day) or !isset($month) or !isset($year))
{
$day = hdate("d");
$month = hdate("m");
$year = hdate("Y");
$curDay = $day;
$curMonth = $month;
$curYear = $year;
} else {
# Make the date valid if day is more then number of days in month
while (!checkdate($curMonth, $curDay, $curYear))
$day--; /// This is line 45 here----------------------------------------------------------------
}

I know this chunk of code works because it is used in another webpage that exists on the production server.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

fredmcfly2 wrote:

Code: Select all

if (!isset($day) or !isset($month) or !isset($year))
Aha.

Those values *are* set (making it to the else statement), but they *are not* checkdate valid.

Before that line, do a var_dump of $day, $month, and $year. I suspect they are blank strings.
fredmcfly2
Forum Newbie
Posts: 9
Joined: Tue Sep 27, 2005 2:41 pm

Post by fredmcfly2 »

I understand what you are saying. What I don't understand is why my webpage works when I have register_globals=off (including this section of code) but when I turn register_globals=on everything stops working, I can't even get the page to load. If $day, $month, $year are blank cause this time out error then shouldn't the webpage NOT work for both cases when register_globals are on AND off?
fredmcfly2
Forum Newbie
Posts: 9
Joined: Tue Sep 27, 2005 2:41 pm

Re: Page doesn't work with register_globals=on

Post by fredmcfly2 »

Roja wrote:
fredmcfly2 wrote:I have develped a webpage on a test server where register_globals=off, but now I am trying to move the page over to a production server where register_globals=on (sadly it's not an option to turn globals off on the production server).
You can turn them off in htaccess files or in the script itself. It is absolutely an option to turn it off, and on a production server, you definitely should: Even if the server itself won't.

What I meant by it isn't an option to turn off globals is that I do not have the authority to turn off the globals and the person who does will not turn off globals because of various and valid reasons.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Page doesn't work with register_globals=on

Post by Roja »

fredmcfly2 wrote:
Roja wrote:
fredmcfly2 wrote:I have develped a webpage on a test server where register_globals=off, but now I am trying to move the page over to a production server where register_globals=on (sadly it's not an option to turn globals off on the production server).
You can turn them off in htaccess files or in the script itself. It is absolutely an option to turn it off, and on a production server, you definitely should: Even if the server itself won't.

What I meant by it isn't an option to turn off globals is that I do not have the authority to turn off the globals and the person who does will not turn off globals because of various and valid reasons.
If you can write a script, you can unset the globals in it. So yes, you do have the authority.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

fredmcfly2 wrote:I understand what you are saying.
Not really, you've misunderstood both of my comments. (and didnt do the var_dump I suggested).
fredmcfly2 wrote:What I don't understand is why my webpage works when I have register_globals=off (including this section of code) but when I turn register_globals=on everything stops working, I can't even get the page to load.
Because its caught in a loop, because your if/else only checks two possibilities - any other, and it locks in a loop.
fredmcfly2 wrote:If $day, $month, $year are blank cause this time out error then shouldn't the webpage NOT work for both cases when register_globals are on AND off?
No. on reg_globals off, the variables ARE NOT SET. In reg_globals on, it appears they are being set, but not to the values you expect.

You need to var_dump them and see what they ARE being set to.
fredmcfly2
Forum Newbie
Posts: 9
Joined: Tue Sep 27, 2005 2:41 pm

Re: Page doesn't work with register_globals=on

Post by fredmcfly2 »

Roja wrote: You can turn them off in htaccess files or in the script itself. It is absolutely an option to turn it off, and on a production server, you definitely should: Even if the server itself won't.
You say I can turn them off in htaccess files, but to my understanding htaccess files only effects Apache ( I very easily could be wrong). Do you have an example how to turn globals off using htaccess files? Or if that won't work how to turn them off in the script?
fredmcfly2
Forum Newbie
Posts: 9
Joined: Tue Sep 27, 2005 2:41 pm

Post by fredmcfly2 »

Roja wrote: Not really, you've misunderstood both of my comments. (and didnt do the var_dump I suggested).
fredmcfly2 wrote:If $day, $month, $year are blank cause this time out error then shouldn't the webpage NOT work for both cases when register_globals are on AND off?
No. on reg_globals off, the variables ARE NOT SET. In reg_globals on, it appears they are being set, but not to the values you expect.

You need to var_dump them and see what they ARE being set to.
Ok I did a var_dump and $day, $month, $year are exactly what I expect them to be; $day = 27, $month = 09, $year = 2005. Even if I hard code valid values in for $day, $month and $year I get the same result.
fredmcfly2
Forum Newbie
Posts: 9
Joined: Tue Sep 27, 2005 2:41 pm

Post by fredmcfly2 »

Ok I am brain dead. I am sorry for not listening to you. You are correct, the first thing I should have done was print out the values. I printed out $day, $month, $year which are correct but I am checking $curDay, $curMonth, $curYear, which after I printed out the values ... they are blank, thus I am getting stuck in the loop like you said. I need to correct this. Thank you for your help. I think I need to see a psychiatrist now.
Post Reply