SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    please help: variable problem

    Hello all

    I have a login.php file in which an user can log in by his name and password. This file has $username and $password variables.

    After login, the user will go to his OWN table, the name of the table the SAME with username.

    User can delete, updata records in this table by using a data.php file. This data.php is used for many users (in the same database). I have to declare $table_name variable so that each user will assign his own table_name by his username.


    I tried but it did not work.......


    Here is what I did

    // login.php file

    $username='username';
    $password = 'password';
    ...
    ...

    ==========

    //data.php file

    $table_name= $username;
    ...
    ...

    ===================
    However, it do not work (may be username is not global variable!!!)

    Could you please help
    Many thanks

    john

  2. #2
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are you passing the variables between the login.php file and the data.php file - are you putting them in user cookies or storing them as sessions?

  3. #3
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello
    No, I did not use them.
    Could you please tell me how to do that

    Thank you
    john

  4. #4
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Before you send anything for output onto the page you will have to call session_start(). This will start a session.
    On the login page, when they login, you will also have to call this. Once called, you'll need to session_register($username) so that, that username is like a global variable for that session. That way when they go to data.php and you have already called session_start() on this page, the session variable $username is present, and so you can use it in your script.

    Remember with sessions that you must start the session before you send anything out onto the page. It might also be helpful to include a logout.php page where the user can log out.

    You could use this on that page:

    session_destroy();

    This will destroy the current session.

    For more information see:
    http://www.php.net/manual/en/ref.session.php


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
  •