SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Hybrid View

  1. #1
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    right I want a user and password system I know how to check passwords etc but how I then pass the info to the other pages that the user is logged in and there username so it can customise the page for them in usch a way that they couldn't just type the url?.
    Garlic bread, I've tasted it, it's the future

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sessions, Sessions and more Sessions.........
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ever one i ask tells me diffrent things I think you are right though but i have no idea how todo them any advice ?
    Garlic bread, I've tasted it, it's the future

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is quite easy, I assume you have a page that looks up the username and password to authenticate the user.

    On that page you need to
    use

    session_start();

    at the top of the page, then after you authenticate the user, you store his/her username in a session variable using

    session_register("username");

    Now on everypage you want to make sure the user is authenticated on you would use

    session_start();
    if(!$username) header("Location: pathtoyourloginpage.php");

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is php4 only right need to check with my host. Thanks alot I will try it later and let you know what a mess i get into .

    Cheers
    Garlic bread, I've tasted it, it's the future

  6. #6
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks for your help so far. I am having a few problems here is the code for the page to check pass and login.

    <?php
    session_start();
    if (isset( $user ) && isset($password)) {
    mysql_connect("localhost", "root", "password");
    mysql_select_db("rapidf1");
    $sql = "SELECT * FROM users WHERE
    user = '$user' AND
    password = '$password'";
    $result = mysql_query( $sql )
    or die ( 'Unable to execute query.' );
    $num = mysql_numrows( $result );
    if ( $num != 0 ) {
    echo 'Your logged in dude';
    }
    }
    session_register("user");
    ?>

    This gives out heaps of errors as shown below

    Warning: Cannot send session cookie - headers already sent

    Warning: Cannot send session cache limiter

    And a few others but I think thats cause the session did not start in the first place.

    Cheers
    Garlic bread, I've tasted it, it's the future

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can we see the whole page it is kinda hard to troubleshoot just seeing this snippet?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that was all the php code but heres the whole file


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>

    </head>

    <body>
    <?php
    session_start();
    if (isset( $user ) && isset($password)) {
    mysql_connect("localhost", "root", "flyingfin");
    mysql_select_db("rapidf1");
    $sql = "SELECT * FROM users WHERE
    user = '$user' AND
    password = '$password'";
    $result = mysql_query( $sql )
    or die ( 'Unable to execute query.' );
    $num = mysql_numrows( $result );
    if ( $num != 0 ) {
    echo 'Your logged in dude';
    }
    }

    session_register("user");
    ?>


    </body>
    </html>
    Garlic bread, I've tasted it, it's the future

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YOu need to put all that session_start() garbage above the <!DOCTYPE line Once the browser starts outputting html it can no longer add header information.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I put a saucer of milk in here will your cat come here a code some php ? :P
    Garlic bread, I've tasted it, it's the future

  11. #11
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: open(/tmp/sess_91dade8b04f4ddba7ad856466220ca2b, O_RDWR) failed: m (2) in e:\sites\rapidf1\login.php on line 2
    Your logged in dude
    Warning: open(/tmp/sess_91dade8b04f4ddba7ad856466220ca2b, O_RDWR) failed: m (2) in Unknown on line 0

    Warning: Failed to write session data. Please check that the current setting of session.save_path is correct (/tmp) in Unknown on line 0

    Hehehe i get that when moving it all about the doctype bit same code didn't wanna repost it all
    Garlic bread, I've tasted it, it's the future

  12. #12
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Milk or bean and cheese burritos he likes both! As for your PHP problem, since yo uare running php on Windows machine, it can't find the /tmp folder which is a unix path. You need to open your php.ini file and change the following line
    session.save_path /tmp

    to session.save_path c:\tmp

    and of course create a folder c:\tmp
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  13. #13
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehehhe man your good Thanks a lot
    Garlic bread, I've tasted it, it's the future


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
  •