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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post Am I missing something?

    Good day,
    Here is a logging code, If the people enter a bad user name and or password it give :

    Undifiened index $LoginName... on line 156

    where $LoginName mean the result of it.

    It execute the script but add that line. I can't figure why cause before I add to the last part of the code it was working perfectly.



    It's been a day that I'm working on that script now !
    Sorry for the long script !





    PHP Code:
    <?php

    $goHere
    ="http://youtoo.com/index.php";    // Page to send successfull log-ins to
    $logSuccess="1";                 // Track / log successful log-ins (1 = yes and 0 = no)

    $namePassCombos = array (        // Add as many lines as you like below

        
    "dude@youtoo" => "admin",      // Add username and password combo here
        
    "dudette@youtoo" => "User01"      // Add username and password combo here

    );

    // Multiple user Log-In script by Dave Lauderdale - Originally published at: www.digi-dl.com

    // The below code may or may not be necessary for you
    $loginName $_POST['loginName']; $passWord $_POST['passWord'];

    // Replace bad characters in user input
    $passWord preg_replace ("/</","[",$passWord); $loginName preg_replace ("/>/","]",$loginName); 
    $loginName str_replace(".."," ",$loginName); $passWord str_replace(".."," ",$passWord);        
      
    // Trim whitespace from user input
    $loginName=trim($loginName); $passWord=trim($passWord);

    // If log-in was successfull -----------------------------------------------------------------------------
    $logInTracker="files/successLog.txt"
    function 
    success($logSuccess,$logInTracker,$loginName,$goHere)
    {
           
    $date=date ("l dS of F Y h:i:s A");
        
    $register_globals = (bool) ini_get('register_gobals');
        if (
    $register_globals$ip getenv(REMOTE_ADDR);
        else 
    $ip $_SERVER['REMOTE_ADDR'];

            
    // If webmaster wants to log successful logins
        
    if($logSuccess=="1"){




    $lines=file($logInTracker);//load the lines to an array
    $insert_line 1;//the line to insert at...could be a post variable
    $insert_text $loginName " as logged in on: " $date " UTC-0 -- Logged IP address: " $ip "\n";
    //this could be a post variable, but at any case make sure to append the var with the new line, otherwise it will run together
    $temp="";//start a temp variable to work with
    $count=1;//initialize a counter


    foreach($lines as $line){
    (
    $count != $insert_line) ? $temp .= $line $temp .= $insert_text $line;
    $count++;
    }


            
    $log=fopen($logInTracker'w');
    $write fwrite($log$temp);
    fclose($log);





        }

            
    // If no log or after log then go here
        
    Header("Location: $goHere");
    }

    // If there is an error --------------------------------------------------------------------------------------
    function error($notice)
    {
            
    // Display error notice (0)-----------------------------
        
    if($notice=="0"){

    $logInTracker="files/successLog.txt"

           
    $date=date ("l dS of F Y h:i:s A");
        
    $register_globals = (bool) ini_get('register_gobals');
        if (
    $register_globals$ip getenv(REMOTE_ADDR);
        else 
    $ip $_SERVER['REMOTE_ADDR'];

            
    // If webmaster wants to log successful logins


    $lines=file($logInTracker);//load the lines to an array
    $insert_line 1;//the line to insert at...could be a post variable
    $insert_text "Empty username or password tried to logged on: " $date " UTC-0 -- IP address: " $ip "\n";
    //this could be a post variable, but at any case make sure to append the var with the new line, otherwise it will run together
    $temp="";//start a temp variable to work with
    $count=1;//initialize a counter


    foreach($lines as $line){
    (
    $count != $insert_line) ? $temp .= $line $temp .= $insert_text $line;
    $count++;
    }


    $log=fopen($logInTracker'w');
    $write fwrite($log$temp);
    fclose($log);


     

            echo
    "
                <title>Log-In Error: Absent username / password</title>
                <body><br><p style=\"font:11pt arial\"><font color=red>NOTICE:</font> Log-In Error: Absent username / password.
                <br><br><br>Click <a href=\"javascript:history.back(1)\" style=\"color:black\">here</a> to try again.
                </body></html>
            "
    ; exit;
        }

            
    // Display error notice (1) ---------------------------------
        
    if($notice=="1"){

    $logInTracker="files/successLog.txt"

           
    $date=date ("l dS of F Y h:i:s A");
        
    $register_globals = (bool) ini_get('register_gobals');
        if (
    $register_globals$ip getenv(REMOTE_ADDR);
        else 
    $ip $_SERVER['REMOTE_ADDR'];

            
    // If webmaster wants to log successful logins

    $lines=file($logInTracker);//load the lines to an array
    $insert_line 1;//the line to insert at...could be a post variable
    $insert_text "Wrong username or password tried to logged on: " $date " UTC-0 -- IP address: " $ip "\n";
    //this could be a post variable, but at any case make sure to append the var with the new line, otherwise it will run together
    $temp="";//start a temp variable to work with
    $count=1;//initialize a counter


    foreach($lines as $line){
    (
    $count != $insert_line) ? $temp .= $line $temp .= $insert_text $line;
    $count++;
    }


    $log=fopen($logInTracker'w');
    $write fwrite($log$temp);
    fclose($log);

            echo
    "
                <title>Log-In Error: Incorrect username / password</title>
                <body><br><p style=\"font:11pt arial\"><font color=red>NOTICE:</font> Log-In Error: Incorrect username / password.
                <br><br><br>Click <a href=\"javascript:history.back(1)\" style=\"color:black\">here</a> to try again.
                </body></html>
            "
    ; exit;
        }
    }

    // If the user doesnt enter a name or password then set error notice to 0 and display error ------------------------------
    if (($loginName == "") || ($passWord == "")) { $notice=0error($notice); }

    // If the username and password entered don't match then set error notice to 1 and display error --------------------------
    else if (strcmp($namePassCombos[$loginName],$passWord) != 0) { $notice=1error($notice); }

    // If the log in was sucessful --------------------------------------------------------------------------------------------
    else if (strcmp($namePassCombos[$loginName],$passWord) == 0) { success($logSuccess,$logInTracker,$loginName,$goHere); 
    session_start();
    $_SESSION['present'] = true;
    }
    ?>

  • #2
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    Here's the answer !
    PHP Code:
    else if (strcmp(@$namePassCombos[$loginName],$passWord) != 0) { $notice=1error($notice); } 
    Thank Noodles23


  •  

    Posting Permissions

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