Hi Guys

I have this little security script, which doesn't work. Everything should be fine so I really can't see the problem.

Here's my script:

<!-- Below is danish tekst -->
Din IP: <?php echo $_SERVER["REMOTE_ADDR"]; ?> er blevet registreret.<br />
Gentagne forsøg på at bryde ind i systemet vil blive anmeldt til politiet.<br /><br />

Your IP: <?php echo $_SERVER["REMOTE_ADDR"]; ?> has been noticed. <br />
Further attempts to break into the system will be reported to the authorities.

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$dato = date("H:i d/m-y");
$fil = $_SERVER['PHP_SELF'];
include('config.php');
con_db();
mysql_query ("INSERT INTO indbrud (ip,dato,fil) VALUES ('$ip','$dato','$fil')");
?>

config.php is a connect-to-mysql script, where con_db() is a function decleared in the same script. That script has been copy-pasted from my other scripts, so I know that it isn't the problem.

The problem is that it doesn't register the log in my MySQL db.

Hope someone of you can see the problem 🙂

Best Regards

Christian S.

    This script should display mysql error message if there is any...

    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    $dato = date("H:i d/m-y");
    $fil = $_SERVER['PHP_SELF'];
    include('config.php');
    con_db();
    $sql = "INSERT INTO indbrud (ip,dato,fil) VALUES ('$ip','$dato','$fil')";
    mysql_query ($sql) or die($sql . ' :: ' . mysql_error());
    ?> 
    

    Hope it helps

      EDIT Konrad beat me to it! dammit!

      But while I'm here, as another tip...

      mysql_query ("INSERT INTO indbrud (ip,dato,fil) VALUES ('$ip', NOW() ,'$fil')");

      instead of getting and formatting a date, (assumnig u are using a date field in mySQL) you can use the NOW() mySQL function in your query, its easier 🙂

        You may have a problem with your DB connection resource.

        con_db();
        $sql = "INSERT INTO indbrud (ip,dato,fil) VALUES ('$ip','$dato','$fil')";
        mysql_query ($sql) or die($sql . ' :: ' . mysql_error());
        

        I'm not sure if the connection I assume you're creating in con_db() will be in the global scope or not. Try returning the resource from the function and using that for your query

        $c = con_db();
        $sql = "INSERT INTO indbrud (ip,dato,fil) VALUES ('$ip','$dato','$fil')";
        mysql_query ($sql,$c) or die($sql . ' :: ' . mysql_error());
          Write a Reply...