Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5

Thread: PHP - Login!

  1. #1
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    this is a login script I installed and I was wondering if anyone could tell me how I could modify this so when a user logs in it will take each user to a different place kinda...

    here is my test info from the db

    member_id
    1

    username
    mbennett

    email
    mbennett@echoterra.com

    say they log in as mbennett which has a member_id of 1 i wanna redirect them to like page.php?id=1 and if it were member_id 2 then redirect them to page.php?id=2

    and i have the rest covered once they go to page.php?id=1 it will call the info from the db (SELECT * FROM stuff WHERE member_id = 1) basically...lol

    so all i need to know is how to change this little login script to redirect the user to their respective page.

    PHP Code:
    <?php

    session_start
    (); 

    // database connection stuff here, get code from earlier tutorials.

    require "admin/config.php";

    $db mysql_connect("$dbhost""$dbuser""$dbpass"); 
    mysql_select_db("$dbname",$db);

    // Do basic checking, input cannot be empty

    if (empty($username) || empty($memberpass))
    {
    die (
    "Error! All fields required.!");
    }

    // Encrypted user submitted password, remember the password stored is encrypted by hash function
    $enc_pass md5($memberpass);

    // Query the database to find matching username, password

    $query "SELECT username, memberpass from members where username='$username' and memberpass='$enc_pass' ";

    $resultmysql_query($query) or die
    (
    "Could not execute query : $query." mysql_error());

    if (
    mysql_num_rows($result) != "0"// username and pass match, authenticate user
    {
    session_register($username); // session register the username
    setcookie ("siteuser",$username,time()+604800); // set cookie containing username 
    Header("Location: catalog.php");



    else { 
    // user is not authenticated
    echo "Error! Username and password does not match or no such user.";
    }

    ?>

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Why not just use:
    PHP Code:
    header("Location: catalog.php?id=$id"); 
    Of course you'll have to get the user's id along with the other information and assign it to $id.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    i did but its not selecting the $id from the db

    So I changed it to

    $query = "SELECT * from members where username='$username' and memberpass='$enc_pass' ";
    $result= mysql_query($query) or die
    ("Could not execute query : $query." . mysql_error());

    $id = ($result["member_id"]);

    and

    Header("Location: page.php?id=$id");

    and i get like

    page.php?id= <--- it doesnt pass the $id

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    You have to do this:
    PHP Code:
    $result mysql_query($query) or die(...);
    $result mysql_fetch_array($result); 
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    Member
    Join Date
    Nov 2002
    Location
    Elmira, NY
    Posts
    41
    Member #
    261
    ok ill give it a shot im a newbie so I tried everything I knew, Im trying to learn so I can help people with their questions


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:35 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com