Jump to content

weird php-behaviour .. need fix

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
denarced

denarced

    Programmer

  • Members
  • PipPipPipPip
  • 182 posts
ok,
2 variables are involved, $_SESSION['tilaus'] ja $tilaus.
when coming to the code I'm posting, both of them contain the same values, which don't themselves matter.
What matters, is that when other is re-created, both of them are zeroed.

        if (isset($_SESSION['tilaus'])) {

                $tilaus = array(); //this zeroes both values

                foreach ($_SESSION['tilaus'] AS $rid => $row) { //you never get to this loop

                        $tilaus[$i++] = $row;

                }

        }


what can cause this ?
can both arrays point to same space in memory like in Java objects ?

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Please don't cuss in your thread titles. It sounds like you have the PHP register_globals directive turned on: PHP: Description of core php.ini directives - Manual

which will cause any superglobal to be registered as a global, IE:

$_POST['data'] is automatically registered as: $data.
$_SESSION['tilaus] is automatically registered as $tilaus.

Taking a look at the session_register value you can find this note:

Quote

If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.


#3
denarced

denarced

    Programmer

  • Members
  • PipPipPipPip
  • 182 posts

Jordan said:

Please don't cuss in your thread titles. It sounds like you have the PHP register_globals directive turned on: PHP: Description of core php.ini directives - Manual

which will cause any superglobal to be registered as a global, IE:

$_POST['data'] is automatically registered as: $data.
$_SESSION['tilaus] is automatically registered as $tilaus.

Taking a look at the session_register value you can find this note:

excellet answer
and fast!
dead on to the point
many thanks for this and slight embarrasment on not knowing this fairly basic thing :)

and no cussing in the future..

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Since register_globals is shunned upon and it is off by default since 4.something, it isn't so bad of a mistake really. In PHP 6.0 it will be removed completely, thank goodness. There are some security risks associated with it.

#5
denarced

denarced

    Programmer

  • Members
  • PipPipPipPip
  • 182 posts
yeah
I was kind of supprised after I read up on register_globals.
And I'll tell you why.
I'm working on this code which stopped working a while back.
It stopped working the minute the servers updated to PHP5.
So when they we're in PHP4, register_globals were off

What's the use anyway for it anyway ?
It can't just be that you have some less typing to do when it's on ..
(althou historically, it's been done .. think of C :D )

#6
denarced

denarced

    Programmer

  • Members
  • PipPipPipPip
  • 182 posts
So we started fixing the problems concerning register_globals($_SESSION['tilaus'] == $tilaus)
but
as we moved along changing things we realized something:

Everything is made in this way => so we have about 50 php files with or without this conflict( lots of require_once()=>lovely :( )

Is there anyway to search for these conflicts ?
unix script perhaps ? (i know some of 'em but ****=>this one would take a wizard)