Professional Web Applications Themes

PHP Session and variable question... - PHP Development

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 ...

  1. #1

    Default 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,


    Rob @ Home Guest

  2. #2

    Default Re: PHP Session and variable question...

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

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

    <?php
    ini_set('display_errors', 1);
    ini_set('log_errors', 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:
    Pedro Guest

  3. #3

    Default 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" <hexkidhotpop.com> wrote in message
    news:gmkslv0qdo4b6us0sbnkfuv5fs6mdmado44ax.com...
    > Rob Home wrote:
    > >Hello,
    > >
    > >I have a really easy (I hope) question but have come you a blocking point
    > >and need some help...
    > [...]
    >
    > try putting these statements at the very top of your pages:
    >
    > <?php
    > ini_set('display_errors', 1);
    > ini_set('log_errors', 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:

    Rob @ Home Guest

  4. #4

    Default Re: PHP Session and variable question...

    Rob Home wrote:
    >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?
    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:
    Pedro Guest

  5. #5

    Default Re: PHP Session and variable question...

    The trick was not including the global $_SESSION

    Thanks

    "Pedro" <hexkidhotpop.com> wrote in message
    news:ihqslvc202qubi28qh8ncn0lp7r8723kdh4ax.com...
    > Rob Home wrote:
    > >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?
    >
    > 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:

    Rob @ Home Guest

  6. #6

    Default 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



    Petey Guest

  7. #7

    Default 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



    Petey Guest

Similar Threads

  1. #39634 [NEW]: session variable and normal variable
    By erhanbaris at gmail dot com in forum PHP Bugs
    Replies: 3
    Last Post: November 27th, 10:09 AM
  2. session variable and URL parameter question
    By Fiogo in forum Coldfusion - Getting Started
    Replies: 0
    Last Post: May 5th, 11:28 AM
  3. Session Variable in IIS 5
    By Sarevalo in forum ASP Components
    Replies: 3
    Last Post: January 22nd, 07:39 AM
  4. Replies: 1
    Last Post: July 17th, 01:35 AM
  5. [SESSION] Session variable deleted prior to command?
    By Ivo Fokkema in forum PHP Development
    Replies: 0
    Last Post: July 16th, 12:59 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139