register globals on

This is a discussion on register globals on within the PHP General forums, part of the PHP Programming Forums category; Hello again, Can I ask a general question? One of the website that we have built was constructed using register ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-12-2006
Zbigniew Szalbot
 
Posts: n/a
Default register globals on

Hello again,

Can I ask a general question? One 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!

--
Zbigniew Szalbot
Reply With Quote
  #2 (permalink)  
Old 09-12-2006
Zbigniew Szalbot
 
Posts: n/a
Default Re: [PHP] register globals on

Hello again,

On 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!

--
Zbigniew Szalbot
Reply With Quote
  #3 (permalink)  
Old 09-12-2006
Larry Garfield
 
Posts: n/a
Default Re: [PHP] register globals on

On Tuesday 12 September 2006 01:16, Zbigniew Szalbot wrote:
> Hello again,
>
> Can I ask a general question? One 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.
$_POST - any parameters passed in the body of a POST query.
$_REQUEST - The two above merged. I forget which takes precedence.
$_COOKIE - Any values sent by the browser as a cookie.
$_SESSION - 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) $GLOBALS[$$key] = $value;
for ($_COOKIE as $key => $value) $GLOBALS[$$key] = $value;

Disabling register globals does not in any way keep you from using cookies.
Of 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 fucking 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. :-)

--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
Reply With Quote
  #4 (permalink)  
Old 09-12-2006
Chris
 
Posts: n/a
Default Re: [PHP] register globals on

Zbigniew Szalbot wrote:
> Hello again,
>
> On 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').

--
Postgresql & php tutorials
http://www.designmagick.com/
Reply With Quote
  #5 (permalink)  
Old 09-12-2006
J R
 
Posts: n/a
Default Re: [PHP] register globals on

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 $_GLOBAL or using globals decleration.

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

function f1()
{
echo $_GLOBAL['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 $_POST, $_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 "$_SESSION". remeber to always start session
"session_start()" on every page.

read more: http://php.net/reserved.variables

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


hth,
john

On 9/12/06, Zbigniew Szalbot <admin@szalbot.homedns.org> wrote:
>
> Hello again,
>
> On 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!
>
> --
> Zbigniew Szalbot
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
GMail Rocks!!!

Reply With Quote
  #6 (permalink)  
Old 09-12-2006
J R
 
Posts: n/a
Default Re: [PHP] register globals on

correction: $GLOBALS not $_GLOBAL

:)

cheers

On 9/12/06, J R <blue.jr@gmail.com> wrote:
>
> 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 $_GLOBAL or using globals decleration.
>
> example:
> $test = 'i'm global';
>
> function f1()
> {
> echo $_GLOBAL['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 $_POST, $_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 "$_SESSION". remeber to always start session
> "session_start()" on every page.
>
> read more: http://php.net/reserved.variables
>
> my advice, avoid using globals. It leads to lots of error that are hard to
> debug and reproduce.
>
>
> hth,
> john
>
>
> On 9/12/06, Zbigniew Szalbot <admin@szalbot.homedns.org> wrote:
> >
> > Hello again,
> >
> > On 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!
> >
> > --
> > Zbigniew Szalbot
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >

>
>
> --
> GMail Rocks!!!
>




--
GMail Rocks!!!

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:29 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0