LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-28-2014, 06:41 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
Unhappy Tearing my hair out! WTF is php doing?


Hey all,

I just encounter some very strange behaviour on my webserver which runs PHP and Apache.

For some reason when viewing this script such as test.php?year=something

The following:
PHP Code:
<?
echo '$year= ' $year;
?>
Will actually output
Code:
$year=something
Somehow it's automatically assigning $_GET variables as standard variables. Is this a feature or something that is turned on or off via a configuration?

I'll also add, I'm not including or source any additional scripts off the server.

Last edited by wh33t; 06-28-2014 at 06:44 PM.
 
Old 06-28-2014, 06:46 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
What version of php/apache?

Older php would do that if REGISTER_GLOBALS was enabled - now deprecated or removed in latest php.

Also, it is not really clear from your post if there is any other wrapper code or preceeding code before the echo.

It isn't really strange, but more common for older php and always configurable.
 
1 members found this post helpful.
Old 06-28-2014, 06:55 PM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
Ahh yes, I just researched it further and concluded it was exactly what you said it was.

I'm not including any other code. It doesn't appear as though I can turn off the register_globals with ini_set either.

Thanks for chiming in.

Last edited by wh33t; 06-28-2014 at 06:56 PM.
 
Old 06-28-2014, 06:57 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
Quote:
Originally Posted by wh33t View Post
This appears to happen because of register_globals.

Strange, I don't ever recall having to deal with this issue before. I wonder if my host just updated the php settings for the server.
Recent php versions do not include register_globals (major security problem) and it was off by default for a few years before that...

Again, what version of php/apache is this?
 
Old 07-03-2014, 05:06 PM   #5
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,056

Rep: Reputation: 78
You cannot turn off register_globals within your script because it has already happened by the time your script begins. You *could* write a loop that unsets any vars which may have been set via register_globals. Something like this would have to run before anything else in your script or you might risk destroying variables that you have actually bothered to define:
Code:
foreach($request as $key => $var) {
  if (isset $$key) {
    unset($$key);
  }
}
 
Old 07-06-2014, 06:07 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by wh33t View Post
Hey all,

I just encounter some very strange behaviour on my webserver which runs PHP and Apache.

For some reason when viewing this script such as test.php?year=something

The following:
PHP Code:
<?
echo '$year= ' $year;
?>
Will actually output
Code:
$year=something
Somehow it's automatically assigning $_GET variables as standard variables. Is this a feature or something that is turned on or off via a configuration?

I'll also add, I'm not including or source any additional scripts off the server.
Try changing to:


PHP Code:
<?php
echo '$year= ' $year;
?>
I think the Apache server changed the default to require the "php" spec rather than assuming it would be PHP.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Tearing Hair Out.. Squid on bridge not forwarding as it should, someone please help! systemlordanubis Linux - Networking 1 04-12-2011 06:10 AM
Intel HDA not working. Tearing my hair out c0mandr Linux - Hardware 4 03-22-2007 10:06 AM
Samba problems - tearing hair ! solar1951 Linux - Networking 5 08-12-2006 12:08 PM
Tearing my hair out!! kcommins Linux - Software 6 08-29-2005 02:36 PM
Tearing My Hair Out: PHP isnt being parsed by Apache 2!! pnh73 Linux - Software 2 01-19-2004 04:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration