Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    session variable trouble

    Hi!
    I am working on a school alumni website. I want to save username in session variable when user Login. I am a new user to php.
    My problem matches with one of your previous post, but not completely.

    session1.php:
    <?php
    session_start();
    session_register("session");
    $session['id']=session_id();
    $session['username']=$userid;
    ?>

    session2.php:
    <?php
    error_reporting(E_ALL);
    echo "The variable stored in the session is ".$_SESSION['username'];
    ?>

    The error is:
    Notice: Undefined index: username in c:\inetpub\wwwroot\phplogincontrol\signup-login\welcome.php on line 29
    The variable stored in the session is

    Thanks in advance.

  • #2
    New Coder bigtiger's Avatar
    Join Date
    Oct 2005
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    session1.php:
    <?php
    session_start();
    session_register("session");
    $session['id']=session_id();
    $session['username']=$userid;
    ?>

    session2.php:
    <?php
    error_reporting(E_ALL);
    echo "The variable stored in the session is ".$_SESSION['username'];
    ?>

    The error is:
    Notice: Undefined index: username in c:\inetpub\wwwroot\phplogincontrol\signup-login\welcome.php on line 29
    The variable stored in the session is

    You should notice this. Is it ?

  • #3
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    still have trouble!

    Hi!
    First of all Thanks for your quick reply!
    Now i have made respective changes in both the files.

    session1.php:
    <?php
    $session['id']=session_id();
    $_SESSION['username']=$userid;
    ?>

    welcome.php:
    <?php
    error_reporting(E_ALL);
    echo "The variable stored in the session is ".$_SESSION['username'];
    ?>

    Now this is working fine. But my trouble comes now.

    The functionality of my application is:
    When User Logins, the UserName will be saved as session variable.
    After his successful Login, a welcome page is displayed.
    Here he can choose an option i.e.
    View Alumni Directory
    Update Account Information
    Contact Us

    Now if User select Update account Info, the UpdateAccount.php page is displayed. When User enter the Info and Click "Update Button" the control is transferred to UpdateAccountck.php page where database connectivity is done.Then a MySql query is executed:

    The code for this page is:
    UpdateAccountck.php:

    <?php>
    error_reporting(E_ALL);
    echo "The variable stored in the session is ".$_SESSION['username'];
    $user = $_SESSION['username'];

    $str = "UPDATE Users SET firstname = '$firstname',middlename = '$middlename',lastname = '$lastname'," .
    " address = '$address', emailaddress = '$email',phoneno = '$phone',year = '$batchyear' where username = $user";
    mysql_query($str,$link);
    ?>

    Here the error comes is:
    Notice: Undefined variable: _SESSION in c:\inetpub\wwwroot\SchoolAlumniWebsite\Project files\UpdateAccountck.php on line 132
    The variable stored in the session is
    Notice: Undefined variable: _SESSION in c:\inetpub\wwwroot\SchoolAlumniWebsite\Project files\UpdateAccountck.php on line 133

    When User Logins, newSession.php is called.
    The code for newSession.php is same
    newsession.php:
    <?php
    $_SESSION['id']=session_id();
    $_SESSION['username']=$user;
    ?>

    Please reply me.

  • #4
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Got the Solution!!

    Hi!
    I myself got the solution for this trouble.
    For every php page i have to start a session at first. i.e.
    session_start()
    So now i can access the session variable on any page by
    echo $_SESSION['username'];

    opelit

  • #5
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Well... my interpretation would be to change your original Source #1 to:

    Code:
    <?php
    session_start();
    session_register("session");
    $id=session_id();
    $username=$userid;
    ?>
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!


  •  

    Posting Permissions

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