Hi
I am trying to write a script that uses aes to encrypt user data but stops the same user from repeatedly polling my script (this wastes my bandwidth). I have the following so far, but unfortunately I get a mysql_fetch_array(): supplied argument is not a valid MySQL result resource error, and my while loop never runs.
Here is my code:
<?php
$time = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$conn=@mysql_connect("*", "*", "*")
or die(mysql_error() . '<center>Sorry, an error has occurred and the main database could not be selected.</center>');
$rs = @mysql_select_db( "technost_site", $conn )
or die( '<center>Sorry, an error has occurred and the main database could not be selected (does it exist?).</center>' );
$sql = "SELECT * FROM `technost_site`.`uses` WHERE `ip` = \"$ip\" ORDER BY `DateTime` desc LIMIT 0, 1;";
$rs = mysql_query($sql) or die ('Error: '.mysql_error ());
while($row = mysql_fetch_array($rs, MYSQL_ASSOC))
{
//Will only ever be one
$to_time=strtotime($time);
$from_time=strtotime($row['DateTime']);
$diff = round(abs($to_time - $from_time) / 60,2);
$diff = $diff * 10;
$num = (int)$diff;
if ($num < 2)
{
$diff = $diff * 10;
$diff = $diff * 5;
die ("Sorry please wait until some time has passed before repeating this. You have waited: " . $diff . "% so far");
}
else
{
include("sql_insert.php");
}
}
//echo ("<a href=\"javascript:document.getElementById('output1').innerHTML = 'Response will go here';\">Clear?</a><br /><br />");
include('Crypt/AES.php');
if ($_POST['key'] == "" || $_POST['text'] == "" || $_POST['output'] == "")
{
die ("Please provide the key, text and output.");
}
$aes = new Crypt_AES();
$key = $_POST['key'];
$aes->setKey($key);
$plaintext = $_POST['text'];
$encrypted = $aes->encrypt($plaintext);
echo ("Key: " . $key . "<br /><br />");
echo ("Plain text:<br />");
echo $aes->decrypt($encrypted);
echo ("<br /><br />Encrypted text ");
if ($_POST['output'] == "base64")
{
echo ("in base64:<br />");
echo (base64_encode($encrypted));
}
if ($_POST['output'] == "base16")
{
echo ("in base16 (hex):<br />");
echo (bin2hex($encrypted));
}
if ($_POST['output'] == "raw")
{
echo ("in raw:<br />");
echo ($encrypted);
}
?>
Could you please give me an insight into what is going on here 🙂. Thanks in Advance.