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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 30

Thread: Authenticate

  1. #1
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts

    Authenticate

    I wrote this code to verify a user and send them to the correct member page. However it doesn't seem to work. What is wrong?

    PHP Code:
    <? 
    /* Check User Script */ 
    session_start();  // Start Session 
    $_SESSION['access'] = "dead"
    header("Cache-control: private"); 

    include 
    'clientarea/config.php'
    // Conver to simple variables 
    $username $_POST['account']; 
    $password $_POST['password']; 

    if((!
    $username) || (!$password)){ 
        echo 
    "Please enter ALL of the information! <br />"
        include 
    'login_form.php'
        exit(); 


    // Convert password to md5 hash 
    // $password = md5($password); 

    // check if the user info validates the db 
    $sql mysql_query("SELECT * FROM dnidesign_clients WHERE username='$username' AND password='$password'"); 
    $login_check mysql_num_rows($sql); 

    if(
    $login_check 0){ 
        while(
    $row mysql_fetch_array($sql)){ 
        foreach( 
    $row AS $key => $val ){ 
            $
    $key stripslashes$val ); 
        } 
            
    // Register some session variables! 
            
    session_register('firstname'); 
            
    $_SESSION['firstname'] = $first_name
            
    session_register('lastname'); 
            
    $_SESSION['lastname'] = $last_name
            
    session_register('email'); 
            
    $_SESSION['email'] = $email_address
            
            
    header("Location: login_success.php"); 
        } 
    } else { 
        echo 
    "You could not be logged in! Either the username and password do not match or you have not validated your membership!<br /> 
        Please try again!<br /> $username $password"

        include 
    'login_form.php'

    ?>
    The main login form is on a different page and the info should be sent to this page to verify it. Any help would be great.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    What isn't working? The query? The session? the login check?

    Btw, session_register() doesn't exist anymore

    You also haven't connected to the database in the code you've shown

  • #3
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    Yes I have connected (inlcude config....). This includes the method for connecting... The login check doesn't want to work, it keeps showing the "Cannot Login" message. I have included the config files as I have it at the moment.
    PHP Code:
    <?php
    ////////////////////////////////////////////
    // Client Area
    // Author: DNI Web Design
    // [url]http://www.dniwebdesign.ca.tt[/url]
    // [email]dniwebdesign@sasktel.net[/email]
    // 
    // CONFIG SCRIPT
    // © 2003 DNI Web Design
    ////////////////////////////////////////////
    // Begin Editable Parameters
    ////////////////////////////////////////////
    // MySQL connection variables    
    ////////////////////////////////////////////
    // Server name that MySQL is on
    $dbhost 'localhost';
    // Login user
    $dbusername '*****';
    // Login password
    $dbpasswd '******';
    // Name of the MySQL database
    $database_name '*****';
    // DO NOT EDIT BELOW THIS LINE
    //-------------------------------------------------------------------------
    //MYSQL CONNECTION
    $connection mysql_pconnect("$dbhost","$dbusername","$dbpasswd"
        or die (
    "Couldn't connect to server.");
        
    $db mysql_select_db("$database_name"$connection)
        or die(
    "Couldn't select database.");
    ?>
    If there is something wrong with this let me know. I belive if you want to see what it is doing check out my website.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Are the passwords in the database encrypted?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    not at the moment...
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #6
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    after
    PHP Code:
    $login_check mysql_num_rows($sql); 
    try adding:
    PHP Code:
     print "The Value of \$login_check = $login_check \n<br/>"
    see what it returns.

  • #7
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    The Value of $login_check =
    You could not be logged in! Either the username and password do not match or you have not validated your membership!
    Please try again!
    Doesn't show a thing...
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #8
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    try replacing the similar line with this:

    PHP Code:
    $sql mysql_query("SELECT * FROM dnidesign_clients WHERE username='$username' AND password='$password'",$connection); 

    and in your config file,

    try changing mysql_pconnect with mysql_connect

    also, you can remove the double quotations (") around the values...ie this would be ok:

    PHP Code:
    $connection mysql_connect($dbhost,$dbusername,$dbpasswd
        or die (
    "Couldn't connect to server."); 

  • #9
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Didn't catch that when I glanced through the first time

    $connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")

    If you are doing that PHP is going to treat those as strings not variables. As Celtboy mentioned remove the quotes from around those.

    Also you really don't need to use pconnect unless you absolutely need a persistent connection. If you do use a persistent connection you need to make sure you don't continue to make new connections and exceed the max number of connections allowed by the mysql configuration or any limits your host has imposed.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #10
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    It still doesn't want to seem to work...
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #11
    Regular Coder
    Join Date
    May 2002
    Location
    Virginia, USA
    Posts
    621
    Thanks
    0
    Thanked 6 Times in 6 Posts
    stick a
    PHP Code:
    print "Testing...<br>\n"
    into your config file. (just making sure it's even including it correctly (the path to the config file may be wrong))

  • #12
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    It prints the testing message...
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #13
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Post the code for you form
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #14
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    As $login_check isn't returning anything, something has got to be wrong with the query or something along those lines.

    As an experiment, try the following:

    PHP Code:
    $sql_str "SELECT * FROM dnidesign_clients WHERE username='$username' AND password='$password'";

    $sql mysql_query("$sql_str",$connection);

    echo 
    $sql_str
    Might also be helpful to show your database setup, maybe something in there is wrong. Can't think of anything else

    <edit>An extra ' appeared from somewhere </edit>
    Last edited by Nightfire; 01-08-2004 at 08:25 PM.

  • #15
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    846
    Thanks
    15
    Thanked 10 Times in 10 Posts
    PHP Code:
    $sql_str "SELECT * FROM dnidesign_clients WHERE username='$username' AND password='$password'";

    $sql mysql_query("$sql_str",$connection);

    echo 
    $sql_str
    That will just print the string $sql_str....

    -------------------
    Login Form


    <form name="form1" method="post" action="checkuser.php">
    <table width="100%" height="79" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td height="16" valign="top" bgcolor="#CCCCCC"><font size="3" face="Arial, Helvetica, sans-serif"><strong><em>Client
    Area</em></strong></font></td>
    </tr>
    <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><font size="2" face="Arial, Helvetica, sans-serif">Account:</font></td>
    <td> <input type="text" style="border-style:solid; border-bottom:1px solid #333366; border-right:1px solid #333366; border-top:1px solid #333366; border-left:1px solid #333366; top-margin=0px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#666666;" size="10" name="account">
    </td>
    </tr>
    <tr>
    <td><font size="2" face="Arial, Helvetica, sans-serif">Password</font></td>
    <td> <input type="password" name="password" style="border-style:solid; border-bottom:1px solid #333366; border-right:1px solid #333366; border-top:1px solid #333366; border-left:1px solid #333366; top-margin=0px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#666666;" size="10">
    </td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <input type="submit" name="Submit" style="border-style:solid; border-bottom:1px solid #333366; border-right:1px solid #333366; border-top:1px solid #333366; border-left:1px solid #333366; top-margin=0px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background: transparent;" value="Enter">
    </div></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </form>



    -------------------
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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