PHP Session and variable question...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob @ Home

    PHP Session and variable question...

    Hello,

    I have a really easy (I hope) question but have come you a blocking point
    and need some help...

    My web page contains both standard HTML and PHP code. No problem there... On
    one page after the user logs in I set a session variable $_SESSION['fName']
    = $fName // $fName is passed to the function. When I draw this page the
    variable in $_SESSION['fName'] echo's correctly and I can go to other pages
    and it will still be there correctly. However, I need more than one variable
    $_SESSION['account']=$eMailAddr where $eMailAddr = their email address. If I
    add this to the code where I set $_SESSION['fName] it all echoes correctly
    on the first page, however, if I got to another page only the ['fName]
    echoes, ['account] does not. Any suggestions? Remember this php code is
    imbedded in an HTML page.

    Thanks,


  • Pedro

    #2
    Re: PHP Session and variable question...

    Rob @ Home wrote:[color=blue]
    >Hello,
    >
    >I have a really easy (I hope) question but have come you a blocking point
    >and need some help...[/color]
    [...]

    try putting these statements at the very top of your pages:

    <?php
    ini_set('displa y_errors', 1);
    ini_set('log_er rors', 0);
    ini_set('error_ reporting', E_ALL);
    ?>



    What they do is set your php to display all errors, warnings and
    notices on the browser (and not log them). After you find the error
    (if it is found this way), remove the lines ...

    ....

    .... or let them in and remove all errors, all warnings, and all
    notices that show up when you run your scripts.



    Happy Coding :-)

    --
    "Yes, I'm positive."
    "Are you sure?"
    "Help, somebody has stolen one of my electrons!"
    Two atoms are talking:

    Comment

    • Rob @ Home

      #3
      Re: PHP Session and variable question...

      Pedro,

      I did this and got "Notice: Undefined index: fName in
      /home/blah/public_html/userFuncs.php line 10"

      line 10 is:
      echo $_SESSION['fName'];

      at the top of the function I call global $_SESSION;

      Does this shed any light?
      Rob


      "Pedro" <hexkid@hotpop. com> wrote in message
      news:gmkslv0qdo 4b6us0sbnkfuv5f s6mdmado4@4ax.c om...[color=blue]
      > Rob @ Home wrote:[color=green]
      > >Hello,
      > >
      > >I have a really easy (I hope) question but have come you a blocking point
      > >and need some help...[/color]
      > [...]
      >
      > try putting these statements at the very top of your pages:
      >
      > <?php
      > ini_set('displa y_errors', 1);
      > ini_set('log_er rors', 0);
      > ini_set('error_ reporting', E_ALL);
      > ?>
      >
      >
      >
      > What they do is set your php to display all errors, warnings and
      > notices on the browser (and not log them). After you find the error
      > (if it is found this way), remove the lines ...
      >
      > ...
      >
      > ... or let them in and remove all errors, all warnings, and all
      > notices that show up when you run your scripts.
      >
      >
      >
      > Happy Coding :-)
      >
      > --
      > "Yes, I'm positive."
      > "Are you sure?"
      > "Help, somebody has stolen one of my electrons!"
      > Two atoms are talking:[/color]


      Comment

      • Pedro

        #4
        Re: PHP Session and variable question...

        Rob @ Home wrote:[color=blue]
        >Pedro,
        >
        >I did this and got "Notice: Undefined index: fName in
        >/home/blah/public_html/userFuncs.php line 10"
        >
        >line 10 is:
        >echo $_SESSION['fName'];
        >
        >at the top of the function I call global $_SESSION;
        >
        >Does this shed any light?[/color]

        You don't need to 'globalize' the _SESSION array

        <?php
        function print_test() {
        echo $_SESSION['test'];
        }

        session_start() ;
        $_SESSION['test'] = 'test ok';
        print_test();
        ?>

        will work very nicely.


        My guess is you have variable names mixed up somewhere in your code.
        Hopefully, seeing all the errors, warnings and notices, would let you
        find the misnamed variables.

        As for your specific error (fName undefined) are you sure you set the
        _SESSION index as "fName" (capitalization matters!!!)

        try outputting all of the _SESSION array right after line 10

        <?php
        // ...
        // line 9
        echo $_SESSION['fName'];
        foreach ($_SESSION as $k => $v) echo $k, ' = ', $v, '<br />';
        // etc. ...
        ?>

        and check the names of the indices you have set versus what you think
        you should have :)

        Pay attention to l, 1, O, 0, ... and capitalization



        --
        "Yes, I'm positive."
        "Are you sure?"
        "Help, somebody has stolen one of my electrons!"
        Two atoms are talking:

        Comment

        • Rob @ Home

          #5
          Re: PHP Session and variable question...

          The trick was not including the global $_SESSION

          Thanks

          "Pedro" <hexkid@hotpop. com> wrote in message
          news:ihqslvc202 qubi28qh8ncn0lp 7r8723kdh@4ax.c om...[color=blue]
          > Rob @ Home wrote:[color=green]
          > >Pedro,
          > >
          > >I did this and got "Notice: Undefined index: fName in
          > >/home/blah/public_html/userFuncs.php line 10"
          > >
          > >line 10 is:
          > >echo $_SESSION['fName'];
          > >
          > >at the top of the function I call global $_SESSION;
          > >
          > >Does this shed any light?[/color]
          >
          > You don't need to 'globalize' the _SESSION array
          >
          > <?php
          > function print_test() {
          > echo $_SESSION['test'];
          > }
          >
          > session_start() ;
          > $_SESSION['test'] = 'test ok';
          > print_test();
          > ?>
          >
          > will work very nicely.
          >
          >
          > My guess is you have variable names mixed up somewhere in your code.
          > Hopefully, seeing all the errors, warnings and notices, would let you
          > find the misnamed variables.
          >
          > As for your specific error (fName undefined) are you sure you set the
          > _SESSION index as "fName" (capitalization matters!!!)
          >
          > try outputting all of the _SESSION array right after line 10
          >
          > <?php
          > // ...
          > // line 9
          > echo $_SESSION['fName'];
          > foreach ($_SESSION as $k => $v) echo $k, ' = ', $v, '<br />';
          > // etc. ...
          > ?>
          >
          > and check the names of the indices you have set versus what you think
          > you should have :)
          >
          > Pay attention to l, 1, O, 0, ... and capitalization
          >
          >
          >
          > --
          > "Yes, I'm positive."
          > "Are you sure?"
          > "Help, somebody has stolen one of my electrons!"
          > Two atoms are talking:[/color]


          Comment

          • Petey

            #6
            Re: PHP Session and variable question...

            Well it should work!

            page1:
            <?
            session_start() ;
            $_SESSION['fName'] = $fName;
            $_SESSION['account'] = $eMailAddr;
            ?>

            page2:
            <?
            session_start() ;
            echo $_SESSION['fName'];
            echo $_SESSION['account'];
            ?>

            logically, that works fine. so if it does not on yours then the problem is
            elsewhere.. you may find that its not even being set because it never
            reaches that part of the code.

            *paste code*
            pasting code makes replies likely to be more accurate :)

            bai bai

            Petey



            Comment

            • Petey

              #7
              Re: PHP Session and variable question...

              Well it should work!

              page1:
              <?
              session_start() ;
              $_SESSION['fName'] = $fName;
              $_SESSION['account'] = $eMailAddr;
              ?>

              page2:
              <?
              session_start() ;
              echo $_SESSION['fName'];
              echo $_SESSION['account'];
              ?>

              logically, that works fine. so if it does not on yours then the problem is
              elsewhere.. you may find that its not even being set because it never
              reaches that part of the code.

              *paste code*
              pasting code makes replies likely to be more accurate :)

              bai bai

              Petey



              Comment

              Working...