SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    NJ/NY
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    foreach loop overwriting my $_SESSION values

    Hey, I'm having a problem with the following code:
    PHP Code:
        $myquery mysql_query("SELECT * FROM blah....");
        foreach(
    mysql_fetch_array($myquery) AS $key=>$val)
            $
    $key $val
    If I have a session variable with the same key as one pulled from the query, the session variable will be set to the newly extracted value.

    For instance, if originally $_SESSION['userid'] equaled 1 and the mysql_fetch_array($myquery) array had a key "userid" that equaled 5, after the foreach loop, $_SESSION['userid'] would become 5. Why does this occur?

    Thanks.

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the register_globals setting enabled?

  3. #3
    SitePoint Addict rabbitdog's Avatar
    Join Date
    Jul 2001
    Location
    So. Tenn.
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it shouldn't when register_globals are off (turn them off, if they're on!). Session variables inhabit entirely different space than local variables.
    Mr Vector
    High quality, royalty free, vector graphics
    for t-shirt artists and graphic/web designers.

  4. #4
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    NJ/NY
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I turn register_globals off? Is there a function I can use, or would I need to contact my host? Thanks again.

  5. #5
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rabbitdog, I know. But that's the only possibility I could think of.

  6. #6
    SitePoint Addict rabbitdog's Avatar
    Join Date
    Jul 2001
    Location
    So. Tenn.
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gaheris - that wasn't directed at you... we wound up posting at almost the same time.

    dtang - in an ideal situation, your host should be in control of setting that (to the right thing!)

    Since we never get the ideal situation, you may check out: http://us3.php.net/manual/en/function.ini-set.php
    Mr Vector
    High quality, royalty free, vector graphics
    for t-shirt artists and graphic/web designers.


Bookmarks

Posting Permissions

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