Global variable turned on

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • waqasahmed996
    New Member
    • Jun 2008
    • 160

    Global variable turned on

    I have just moved to a new server and apparently I cannot use global variables as I used to. I would like to reenable this as it was in teh past.

    I guess that there is a setting called global_variable s that is set to "off" by default. How do I set this to "on"? I have root access on this server so there should be no problem with me being able to change this setting if I knew how.

    actually my problem is that first i am able to use $username instead of $_POST['username'].
    But on another server me not able to access like that
    please tell me what changes i have to do


    Thanks very much.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    You can edit your php configuration, if you have access to your php.ini file (config file).

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      my advice: keep it like it is. register_global s was turned off because of security reasons (see PHP: Using Register Globals - Manual). and you're writing much cleaner code when using the apropriate superglobals ($_GET, $_POST, $_COOKIE, ...)

      if you indeed need global data, you may consider using a class for that (e.g. the abstract registry pattern)

      regards

      Comment

      • waqasahmed996
        New Member
        • Jun 2008
        • 160

        #4
        thanks for reply

        i have to on global variable

        i made changes in php.ini file as register_global s = On

        and also in .htaccess file as php_flag register_global s on

        but still global variable is off

        please tell me whether this function is available for PHP version 5.2.5 or not????

        because i am using PHP version 5.2.5

        thanks

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          did you restart the server? you need the changes loaded.

          I still advice to use register_global s off.

          and of PHP6 register_global s will be dropped.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            You can turn register_global s on in all versions of PHP 5, but this is highly discouraged. It enables very bad coding habits and can potentially pose a huge security risk.

            If you have no alternative but to turn it on, all you would have to do is change your php.ini to:
            Code:
            register_globals = on
            And restart the server, of course.

            If for some reason this is giving you trouble, and you absolutely have to have these variables in the global scope, you can use the extract function to simulate this behavior.
            For example, this would print a field named "field1" submitted via the POST protocol:
            [code=php]
            <?php
            extract($_POST) ;
            echo $field1;
            ?>[/code]
            Note that I DO NOT RECOMMEND THIS, but it is an option if you absolutely have no other choice.

            Comment

            • waqasahmed996
              New Member
              • Jun 2008
              • 160

              #7
              Thanx.You really give me good solutions
              Thanks again

              Comment

              Working...