PHP

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • register globals on

    6 answers - 1135 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hello again,
    Can I ask a general question? of the website that we have built was
    constructed using register globals. Thanks to that we set the language for
    browsing the website by determining user's browser language and then also
    (I think) it is used to remember some other choices users make while on
    the website (especially the language for browsing).
    Anyway, our ISP asks us to stop using register globals. They are right. We
    should. However, the programmer we have been using to help us, insists
    that without register globals on, we will have to revert to using cookies.
    This - he claims - is not an option because if a user blocks cookies, site
    as such will become useless (many options on the website are a consequence
    of setting the language first).
    I thought I would ask your opinion before we make any decision. Is it
    really so that without register globals, such things as displaying
    information from databases based on the initial choice of languages is not
    an option? I am not a programmer so I just need general guidance.
    Thank you very much in advance!
  • No.1 | | 1170 bytes | |

    Zbigniew Szalbot wrote:
    Hello again,

    Can I ask a general question? of the website that we have built was
    constructed using register globals. Thanks to that we set the language for
    browsing the website by determining user's browser language and then also
    (I think) it is used to remember some other choices users make while on
    the website (especially the language for browsing).

    Anyway, our ISP asks us to stop using register globals. They are right. We
    should. However, the programmer we have been using to help us, insists
    that without register globals on, we will have to revert to using cookies.
    This - he claims - is not an option because if a user blocks cookies, site
    as such will become useless (many options on the website are a consequence
    of setting the language first).

    I thought I would ask your opinion before we make any decision. Is it
    really so that without register globals, such things as displaying
    information from databases based on the initial choice of languages is not
    an option? I am not a programmer so I just need general guidance.

    Complete rubbish. He's being lazy.
  • No.2 | | 606 bytes | |

    Hello again,

    Tue, 12 Sep 2006, Chris wrote:

    I thought I would ask your opinion before we make any decision. Is it
    really so that without register globals, such things as displaying
    information from databases based on the initial choice of languages is not
    an option? I am not a programmer so I just need general guidance.

    Complete rubbish. He's being lazy.

    Thanks a lot! Any hint what to use instead? I mean I will tell him to
    re-think things but with techi guys I would simply feel better saying we
    need to rework the website using?

    Thank you again!
  • No.3 | | 3159 bytes | |

    Tuesday 12 September 2006 01:16, Zbigniew Szalbot wrote:
    Hello again,

    Can I ask a general question? of the website that we have built was
    constructed using register globals. Thanks to that we set the language for
    browsing the website by determining user's browser language and then also
    (I think) it is used to remember some other choices users make while on
    the website (especially the language for browsing).

    Anyway, our ISP asks us to stop using register globals. They are right. We
    should. However, the programmer we have been using to help us, insists
    that without register globals on, we will have to revert to using cookies.
    This - he claims - is not an option because if a user blocks cookies, site
    as such will become useless (many options on the website are a consequence
    of setting the language first).

    I thought I would ask your opinion before we make any decision. Is it
    really so that without register globals, such things as displaying
    information from databases based on the initial choice of languages is not
    an option? I am not a programmer so I just need general guidance.

    Thank you very much in advance!

    Your programmer is (a) lying (b) completely and totally clueless (c) both.
    (Choose one.)

    In any vaguely recent version of PHP, you get five super-global array
    variables:

    $_GET - any parameters passed in the GET string.
    $_PST - any parameters passed in the body of a PST query.
    $_REQUEST - The two above merged. I forget which takes precedence.
    $_CKIE - Any values sent by the browser as a cookie.
    $_SESSIN - Any values that you have saved to the session array, which is
    (usually) persisted on the client's browser as a session cookie.

    All register globals does is take the contents of those arrays and dump them
    into the global namespace. (Again, I forget off hand what the precedence
    is.) You can very easily simulate register globals (which you should never
    do) with:

    for ($_REQUEST as $key =$value) $GLBALS[$$key] = $value;
    for ($_CKIE as $key =$value) $GLBALS[$$key] = $value;

    Disabling register globals does not in any way keep you from using cookies.
    course, 90% of the time if you're using cookies, you REALLY mean to be
    using a session instead. Remembering a user's setting, such as what language
    they want, is a text-book example of where you want to be using sessions.
    Register globals is not required for that in any way shape or form.

    It may well be the case that refactoring your code to not depend on register
    globals will be difficult, time consuming, or annoying. That's quite
    possible. But that has nothing to do with cookies. Nor is there any way for
    you to persist data between page loads using register globals in the first
    place. Your programmer is full of it.

    As for a user disabling cookies, my honest opinion is that it's ****ing 2006,
    if someone is so paranoid that they're blocking on-site session cookies then
    they shouldn't be allowed to use a web browser in the first place. :-)
  • No.4 | | 1583 bytes | |

    Zbigniew Szalbot wrote:
    Hello again,

    Tue, 12 Sep 2006, Chris wrote:

    I thought I would ask your opinion before we make any decision. Is it
    really so that without register globals, such things as displaying
    information from databases based on the initial choice of languages is not
    an option? I am not a programmer so I just need general guidance.
    >Complete rubbish. He's being lazy.


    Thanks a lot! Any hint what to use instead? I mean I will tell him to
    re-think things but with techi guys I would simply feel better saying we
    need to rework the website using?

    No real hint about what to use instead, we don't know the code.

    At a guess he's doing something like:

    <?php

    $lang_file = $lang . '.php';
    include($lang_file);

    What he should be doing:

    <?php
    $default_language = 'en';
    $valid_languages = array('en', 'fr');

    if (isset($_GET['lang'])) {
    $lang_chosen = $_GET['lang'];
    } else {
    $lang_chosen = $default_language;
    }

    if (!in_array($lang_chosen, $valid_languages)) {
    $lang_chosen = $default_language;
    }

    include($lang_chosen . '.php');

    What that does is checks to see if there is a 'lang=' in the url.

    If there is, it makes sure it's valid (in this case either 'en' or 'fr').

    If it's not set or it's not valid, then it uses the default language ('en').
  • No.5 | | 1721 bytes | |

    there are many ways you can keep information.

    now if you must really use global. you can still use global even if the
    server is set to global off by using $_GLBAL or using globals decleration.

    example:
    $test = 'i'm global';

    function f1()
    {
    echo $_GLBAL['test']; // should display i'm global
    }

    function f2()
    {
    global $test;
    echo $test; // should display i'm global
    }

    now for your forms. i'm not sure is the above will work (to lazy to verify
    :)) use the other predefined variables like $_PST, $_GET, $_REQUEST thats
    where data from your forms are stored when the page is submited. and if you
    want to keep your data when your user move from one page to the other, store
    it in a session "$_SESSIN". remeber to always start session
    "session_start()" on every page.

    read more:

    my advice, avoid using globals. It leads to lots of error that are hard to
    debug and reproduce.

    hth,
    john

    9/12/06, Zbigniew Szalbot <admin (AT) szalbot (DOT) homedns.orgwrote:

    Hello again,

    Tue, 12 Sep 2006, Chris wrote:

    I thought I would ask your opinion before we make any decision. Is it
    really so that without register globals, such things as displaying
    information from databases based on the initial choice of languages is
    not
    an option? I am not a programmer so I just need general guidance.

    Complete rubbish. He's being lazy.

    Thanks a lot! Any hint what to use instead? I mean I will tell him to
    re-think things but with techi guys I would simply feel better saying we
    need to rework the website using?

    Thank you again!
  • No.6 | | 1853 bytes | |

    correction: $GLBALS not $_GLBAL

    :)

    cheers

    9/12/06, J R <blue.jr (AT) gmail (DOT) comwrote:

    there are many ways you can keep information.

    now if you must really use global. you can still use global even if the
    server is set to global off by using $_GLBAL or using globals decleration.

    example:
    $test = 'i'm global';

    function f1()
    {
    echo $_GLBAL['test']; // should display i'm global
    }

    function f2()
    {
    global $test;
    echo $test; // should display i'm global
    }
    --
    now for your forms. i'm not sure is the above will work (to lazy to verify
    :)) use the other predefined variables like $_PST, $_GET, $_REQUEST thats
    where data from your forms are stored when the page is submited. and if you
    want to keep your data when your user move from one page to the other, store
    it in a session "$_SESSIN". remeber to always start session
    "session_start()" on every page.

    read more:

    my advice, avoid using globals. It leads to lots of error that are hard to
    debug and reproduce.
    --
    hth,
    john
    --
    9/12/06, Zbigniew Szalbot <admin (AT) szalbot (DOT) homedns.orgwrote:

    Hello again,

    Tue, 12 Sep 2006, Chris wrote:

    I thought I would ask your opinion before we make any decision. Is
    it
    really so that without register globals, such things as displaying
    information from databases based on the initial choice of languages
    is not
    an option? I am not a programmer so I just need general guidance.

    Complete rubbish. He's being lazy.

    Thanks a lot! Any hint what to use instead? I mean I will tell him to
    re-think things but with techi guys I would simply feel better saying we

    need to rework the website using?

    Thank you again!

Re: register globals on


max 4000 letters.
Your nickname that display:
In order to stop the spam: 8 + 7 =
QUESTION ON "PHP"

EMSDN.COM