#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0

    Display username after login.


    Hello,

    I want to display the username after loggin into my next page.

    But i am getting this error.

    This is my code

    <?php
    $s_name=$_SESSION['name'];

    hello <?php echo $s_name; ?>

    I am getting undefined name error.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    well, what are we supposed to do with that code snippet? It really doesn't tell us anything.

    Have you called session_start() before working with $_SESSION? If so, what does var_dump($_SESSION) say?

    And don't dump variables directly into your HTML. Bad guys will happily use this to inject JavaScript into the page and steal session IDs and whatnot. Use htmlentities().
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    well, what are we supposed to do with that code snippet? It really doesn't tell us anything.

    Have you called session_start() before working with $_SESSION? If so, what does var_dump($_SESSION) say?

    And don't dump variables directly into your HTML. Bad guys will happily use this to inject JavaScript into the page and steal session IDs and whatnot. Use htmlentities().
    Yes , i declared session_start() also in the first line.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    And what does the $_SESSION array contain then?

    (Please don't quote the full reply)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    Originally Posted by simbu
    Yes , i declared session_start() also in the first line.
    I am getting this erroe.

    Notice() Undefined index:name C:\\wamp\www\.....
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    Sorry , i Cant understand what u r saying?$_SESSION['name'] contain means?


    Actually i want to display the username after logging in so i declared as a name into $s_name.
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Originally Posted by simbu
    Sorry , i Cant understand what u r saying?$_SESSION['name'] contain means?
    I'm asking you to output the content of the $_SESSION array and show it here. Call var_dump($_SESSION); as explained above.

    Obviously the array does not have a 'name' entry. So the question is: What does it contain? Is it maybe empty because you didn't set any session values at all?

    The only way to find that out is to actually check the content.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    Originally Posted by Jacques1
    I'm asking you to output the content of the $_SESSION array and show it here. Call var_dump($_SESSION); as explained above.

    Obviously the array does not have a 'name' entry. So the question is: What does it contain? Is it maybe empty because you didn't set any session values at all?

    The only way to find that out is to actually check the content.
    The array name is username and i created as a name contact form.

    Here is my main page
    <tr>
    <td valign="top">
    <label for="your name">Your Name :<font color="red">* </font></label>
    </td>
    <td valign="top">
    <input type="text" name="name" placeholder="Enter your name" required maxlength="30" size="30" />
    </td>
    </tr>

    <tr>
    <td valign="top">
    <label for="password">password :<font color="red">* </font></label>
    </td>
    <td valign="top">
    <input type="password" name="password" placeholder="Enter your password" required maxlength="30" size="30" />
    </td>
    </tr>
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    the array name is username logged in from login form.
  18. #10
  19. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    I asked you for a specific info (three times already). I you don't want to or aren't able to copy and paste this var_dump() into your code, we cannot help you.

    Many people seem to think we are some kind of psychics that will solve any error just by seeing the error message and a random code snippet. Unfortunely, we are all just human beings without any magical abilities. And that's why we need specific data to be able to analyze a problem.

    The first thing is the content of the array. With that I mean the actual elements, not a general description of what should be there.

    And we'll be probably need the code where you set the session values.
    Last edited by Jacques1; November 22nd, 2012 at 08:21 AM.

IMN logo majestic logo threadwatch logo seochat tools logo