Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Support > php issues.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-17-2007, 07:03 PM
Member
 
Join Date: Nov 2007
Posts: 33
Default Register_globals, a basic question

I have been reading a few threads and the consensus seams to be that having register_globals turned on is a security risk. The majority of pages on my site use the $_POST method to pass form data but, with register_globals turned off, everything falls over.

My question is this... Ho do I get around the problem? Or do I just turn on register_globals?

Many thanks for your input,

Scottie
Reply With Quote
  #2 (permalink)  
Old 11-17-2007, 09:27 PM
Dan's Avatar
Dan Dan is offline
Guru
 
Join Date: Aug 2007
Location: England, UK.
Posts: 686
Default

I'm not too sure on this one. I just go and do what needs to be done. I've never encountered such a problem with register globals so it's hard to give an explanation.
__________________
Webhosting.UK.com || cPanel VPS Hosting || Reseller Hosting || Support System || Billing System

Sales: 0808-262-0855
Support: 0800-612-8725
International: +44 191 303 8191
Reply With Quote
  #3 (permalink)  
Old 11-17-2007, 10:34 PM
Member
 
Join Date: Mar 2007
Location: Bristol, UK
Posts: 32
Default

scottie2212, who are you accessing the data that is sent via POST?

With register_globals turned on all the variables sent via GET or POST (as well as others) are directly acessible as $foo.

e.g. visiting:
example.com/index.php?foo=bar

echo $foo;

This would return "bar".

So with register_globals turned on the variables are accessible easily but there is a security risk. If you don't initialise all your variables people could inject malicious values into them.

With register_globals turned off GET, POST (and the others) are only accessible via $_GET["foo"], $_POST["foo"], etc.

If the code is falling over with register_globals turned off then make sure there's no code that is relying on the variables ($foo) automatically being set.
Reply With Quote
  #4 (permalink)  
Old 11-17-2007, 10:59 PM
Member
 
Join Date: Nov 2007
Posts: 33
Default

Thanks for the reply,

I've done some more testing of this and clarified what is actually happening but I still don't know why or how to get around it.
This is a snippet of code from my logon page -

echo "test of name " . $_POST['name'];
if ($REQUEST_METHOD=="POST") {
$fooname = trim(strip_tags($_POST['name']));
echo "the name is $fooname";

With register globals turned on I see the output of both echo commands along with the variables but when it's turned off I only see output from the first with it's variable.
Obviously the $_POST['var'] is being passed but not the REQUEST_METHOD. I can't understand this because I though the $_POST was a part of the REQUEST_METHOD array.

If this makes it more understandable to you and you can help me resolve it I would be very grateful.

Scottie
Reply With Quote
  #5 (permalink)  
Old 11-18-2007, 12:00 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

$REQUEST_METHOD isn't an array AFAIK. Its part of the $_SERVER array and there isnt any guarantee that the variables in that array will always be present.

Why not just use :
if($_POST)
{
//blah blah
}
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #6 (permalink)  
Old 11-18-2007, 12:26 PM
Member
 
Join Date: Nov 2007
Posts: 33
Default

Thanks for that Kev, it makes more sense now.

I'm not certain that I can apply your suggestion to all my pages as some of them have numerous functions governed by the the value of $_POST['button_name'] but I will certainly go through them now and see if I can remove all the REQUEST_METHOD conditions.

At least I now have a point of attack.

Scottie.
Reply With Quote
  #7 (permalink)  
Old 11-18-2007, 06:35 PM
Member
 
Join Date: Nov 2007
Posts: 33
Default

Just an update.

Thanks to Kev's info, I've now got all my pages working with register_globals turned off and I have a better understanding of these things.

Thanks Kev

Scottie.
Reply With Quote
  #8 (permalink)  
Old 11-18-2007, 10:38 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

no problem fella - glad it all worked out
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #9 (permalink)  
Old 11-19-2007, 10:52 AM
Member
 
Join Date: Mar 2007
Location: Bristol, UK
Posts: 32
Default

Quote:
Originally Posted by kev woodman View Post
Why not just use :
if($_POST)
{
//blah blah
}
Or a more desirable method would be:
if ($_SERVER['REQUEST_METHOD']=="POST")
{
//blah blah
}

I should have explained when I said "(as well as others)" I also meant the $_SERVER variables.
Reply With Quote
  #10 (permalink)  
Old 11-19-2007, 10:57 AM
Member
 
Join Date: Nov 2007
Posts: 33
Default

Thanks for the update Kev, (edited, Sorry Dave, I've never been any good with names)

That explains why I couldn't get the ip address logging to work. Now I can look at that again.

Last edited by scottie2212; 11-19-2007 at 11:02 AM. Reason: senility
Reply With Quote
  #11 (permalink)  
Old 11-19-2007, 10:58 AM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Would that be better Dave?

The elements of the $_SERVER array are dependent on the server so really you would have to check if REQUEST_METHOD is set and then check for its value.

What would be the advantage of accessing $_SERVER?
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #12 (permalink)  
Old 01-18-2008, 01:37 PM
Foddski's Avatar
new member
 
Join Date: Nov 2007
Posts: 9
Default

On pages with forms I tend to use
Quote:
if ($_POST)//Detects a posting
{ $subject = stripslashes($_POST['subject']);}
So i don't set any variables until the form data is submitted.
Reply With Quote
  #13 (permalink)  
Old 01-19-2008, 05:57 AM
Member
 
Join Date: Jan 2008
Posts: 50
Default

You can emulate register globals as turned on by adding this to your .htaccess

php_flag register_globals on
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:54 AM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum