Results 1 to 16 of 16

Thread: ugh and register_globals..

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    ugh and register_globals..

    ok, my local system doesn't have register_globals on, but my web host does.. is there any simple line of code that i can put at the top of my config scripts that will turn it off? it's making an entire website of mine not work correctly.. and it's just annoying seeing as how any server i've ever used in the past did not have it on.
    Like Archer? Check out some Sterling Archer quotes.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    hmm, nevermind.. looked up register_globals on PHP.net and found this nifty code:
    PHP Code:
    <?
      $var_list = get_defined_vars();
      $safelist = array('_GET', '_POST', '_COOKIE', '_SERVER', '_ENV', '_FILES', '_REQUEST');
      foreach($var_list as $name => $value){
        if(array_search($name, $safelist) === FALSE){
          unset($$name);    
        }
      }
      unset($var_list, $name, $value, $safelist);
    ?>
    it's a life saver..
    Like Archer? Check out some Sterling Archer quotes.

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Why not:

    PHP Code:
    <?php
        ini_set
    ("register_globals""0");
    ?>
    At the top of the script?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331
    cause that wil only do that instance of the script, not the whole site.

    best bet is to have them turn it off.

    how is tha tcode helping? all you did was unset them which means you made them 0 I don't see anywhere where that comes in handy?

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    phpman, I swear...

    Originally posted by phpman
    cause that wil only do that instance of the script, not the whole site.
    And if he does that for every script, no problem.

    Originally posted by phpman
    best bet is to have them turn it off.
    You know nothing about business, do you phpman? A hosting company isn't going to change a variable such as register_globals just because one member requests it. If they have thousands of customers, then hundreds of scripts that relied on register_globals will stop working.

    I know you're going to come back and say "too bad, code applications right", but that isn't going to fly and isn't very good business.

    Originally posted by phpman
    how is tha tcode helping? all you did was unset them which means you made them 0 I don't see anywhere where that comes in handy?
    The code unsets any global variable that isn't in his safe list. Looks very handy to me, but using ini_set() does the same thing with less lines of code.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331
    like I knew it was a HOST that has many users. funny I asked mine to be turned off and they id it. many users on that system and no one complained. so every situation is differnet.

    and yes I see it unsets any gloabls that is not used, but what does it do for register_globals? nothing. you still can't use $_POST very well.

    And if he does that for every script, no problem.
    and you think it works like that? no. maybe it works for other settings but not globals.

    unless I am looking at it wrong it does nothing, you still have to use $HTTP_POST_VAR instead of $_POST

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    and yes I see it unsets any gloabls that is not used, but what does it do for register_globals? nothing. you still can't use $_POST very well.
    Yes, you can, actually.

    Originally posted by phpman
    and you think it works like that? no. maybe it works for other settings but not globals.
    I know for a fact that it does work like that. Matt (cpradio)'s cpCommerce does this. Works like a charm. There's my proof. Where's your proof that it doesn't work?

    Originally posted by phpman
    unless I am looking at it wrong it does nothing, you still have to use $HTTP_POST_VAR instead of $_POST
    Huh? You must be looking at it wrong.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331
    I totally forgot that nothing goes wrong with you. you are a php god and know it all.

    for one, if you want to use globals with the globals ON it will mess up once in awhile, but I am not going to prove it to you cause I don' have a working system with gloabals on. it happend to me so there. two, I read it on another forum and experienced it myself.

    I don't have to prove anything to you, you don't have anything go wrong.

    answer my thread if you know it all. although it may not happen to you, things happend, every server is different. hence my thread.

    but yes if you want globals off then do your post, but that code he posted doesn't make it so globals are off.

  9. #9
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331
    so tell me hobo, if globals doesn't make a difference than why for the post

    ok, my local system doesn't have register_globals on, but my web host does.. is there any simple line of code that i can put at the top of my config scripts that will turn it off? it's making an entire website of mine not work correctly
    explain that to me??? hence you can't you $_POST on a site that globals are on.... sometimes it works sometimes it doesn't.

    but to fix the problem you could do soemthing like this

    PHP Code:
    foreach ($HTTP_POST_VARS as $key => $val) {
          $
    $key $val;
      }

    OR

    foreach (
    $HTTP_POST_VARS as $key => $val) {
          
    $_POST['$key'] = $val;
      } 
    will allow you to use the regular variables if you don't want to replace your code. you can do the same for cookies too I believe.

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You might want to reconsider your tone phpman. What you complain about has nothing to do with Hobo's post.

    explain that to me???
    The problem is that the registered globals interfere with his own globals, which was the reason why register_globals now defaults to off anyway.

    The $_POST vs $HTTP_POST_VARS issue is only one of the PHP version and has nothing to do with the issue discussed here, which is how to get rid of the registered globals.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    I totally forgot that nothing goes wrong with you. you are a php god and know it all.
    Whatever, dude. Things go wrong with me all the time. My applications are riddled with bugs and sometimes I get caught up on the stupidest things. Stuff goes wrong all the time.

    But the funny thing is, you've been saying stuff to me for years like "if you do this, this will go wrong" and it never does. The stuff that you tell me wont work, works.

    If you believe that I have a "nothing goes wrong for me" attitude, then I'll air my opinion that you have a "my opinion is fact" attitude.

    On all accounts where I call you out on something, you've NEVER provided me proof of why something wont work.

    Originally posted by phpman
    for one, if you want to use globals with the globals ON it will mess up once in awhile, but I am not going to prove it to you cause I don' have a working system with gloabals on. it happend to me so there. two, I read it on another forum and experienced it myself.
    I'm not trying to arguing that using PHP with register_globals on is good. I'm a firm believer that it should be shut off. I just understand that there are often circumstances where it can't be.

    Originally posted by phpman
    I don't have to prove anything to you, you don't have anything go wrong.
    I'm sorry, but I'm not someone who follows blindly. If you tell me there's wet paint, I'm going to touch it. If I don't get paint on my hands, I'm going to question you.

    If you tell me that doing something one way will yield a certain result, and I don't get that result, I'm going to question you. And I do. And you never provide any evidence.

    Originally posted by phpman
    answer my thread if you know it all. although it may not happen to you, things happend, every server is different. hence my thread.
    I never once stated to know it all, nor do I act that way. If I knew it all, why have I posted so many questions?

    I'm not trying to act like I know it all. I'm asking you for proof. You say something happens, I say "let me see."

    Originally posted by phpman
    but yes if you want globals off then do your post, but that code he posted doesn't make it so globals are off.
    He (nor I) never said that it would shut globals off. It will, however, unregister global variables that he doesn't want, and ones that are causing problems with his script.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    so tell me hobo, if globals doesn't make a difference than why for the post
    I'll answer that question when you tell me where I said that globals don't make a difference. Sound fair?

    Stop putting words in my mouth. You've done it about 8 times in this thread. It's getting tiring.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331
    on my system if globals are on and I used $_POST in my code it would be blank. if I turn globals off it works fine. but like I said it was sparatic, it never happend all the time. it may have well been a bug in php for all I know.

    as far as globals working like that, I will point you to the thread that told me as I asked the same question when my host had globals on, and the main guy for vbulliten told me it doesn't work that way. but after searching the site they lost a lot of threads ever since vb3 came out. I think they updated the site and got rid of old posts.

    I will provide you proof anytime you want, but like I said, every system is different and if it happens on my machine and not yours then how good is my proof? I don't say things don't work if I haven't seen it with my own eyes. like my post, I see nobody has answered it???

    I will write something up and see if I can make it happen.

  14. #14
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,331
    Originally posted by The Hobo
    I'll answer that question when you tell me where I said that globals don't make a difference. Sound fair?

    Stop putting words in my mouth. You've done it about 8 times in this thread. It's getting tiring.
    because you said you can still use $_POST with globals on.

    Yes, you can, actually.

    if he writes some code that uses $_SESSION or any of the others and his host has globals on then how do those work if you unset the regular variables in that code?

  15. #15
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    because you said you can still use $_POST with globals on.
    You can, dude. I've been using HostingMatters as my host for a year or two now, and they have register_globals ON. They always have had it on.

    I use $_POST, $_COOKIE, etc in my scripts, with register_globals on, and it works fine. I've never had a problem with it.

    Do you want me to write something up and put it on my server so you can see that it works for me?

    And saying "you can still use $_POST with globals on" is not the same as saying "globals don't matter."

    Originally posted by phpman
    if he writes some code that uses $_SESSION or any of the others and his host has globals on then how do those work if you unset the regular variables in that code?
    His code will unset EVERYTHING BUT

    array('_GET', '_POST', '_COOKIE', '_SERVER', '_ENV', '_FILES', '_REQUEST')
    What do you not understand?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    $_POST, $_GET, $_COOKIE, and any other global variables like that work fine; I never once said they didn't. The problem with my script is that I have $_POST['user'] and $_POST['pass'], and when I 'clean' the name I define it as $user, and then when I encrypt the password before I put it into a cookie/database I define it as $pass.. this screws up the definitions of the variables and makes none of my scripts work.

    The global variables work fine with and without register_globals on. This may not have been so pre-PHP 4, but I was a Perl nut and only started PHP less than a year ago, so that's all I've used and it's always worked the same.
    Like Archer? Check out some Sterling Archer quotes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width