1. MySQL is free, fairly easy to use and is way better than using a text file.

2. I would use something to effect of a 'id' field in the database and set that to be indexed, auto-incrementing and unique vs. using your 'public key' as the indexed portion of the database

3. Sounds like you already know what kind of function you need. If you need an example here is one.
[snippit]
<?php
function keys() {
/* Connect to database */
$db = @mysql_pconnect('localhost','user_name','password') or die(mysql_error());
/* Select databse to use */
@mysql_select_db('keys') or die("Could not connect to remote database.");
$tble = "messages";
/* Look for existing key */
$sql = mysql_query("SELECT * FROM $tble WHERE key = '$key'",$db)or die(mysql_error());
/* Create array of variables retrieved */
while ($row = mysql_fetch_array($sql)) {
$id = $row["session"]; }
/* Check to see if any results were returned */
if (mysql_num_rows($sql) == 0) {
$insert = @mysql_query("INSERT INTO $tble VALUES ('','$var1','$var2','$var3','$var4','$var5')",$db)or die(mysql_error());
/* If key exists update data with form data */
} elseif (mysql_num_rows($sql) != 0) {
$update = @mysql_query("UPDATE $tble SET var1=\"$var1\", var2=\"$var2\", var3=\"$var3\", var4=\"$var4\", var5=\"$var5\" WHERE key=\"$key\"",$db)or die(mysql_error());
} else {
exit(); }
} else {
exit(); }
}
?>
[end snippit]


4. You are talking about a one way hash to be used as a public key right? If you are I generate a unique key in this manner (I really don't loop through any array's of numbers or letters) instead I pull an image randomly selected from a specified directory and then through it through a system of functions as illustrated below. You can record the key in the database and use it as a "public key" so to speak so the person your sending the secret message to would need to know that "public key".
[snippit]
<?php
/* Function to create array of images */
$rand_image = array();
$x = 0;
$x++; $rand_image[$x] = "shared/image01.jpg";
$x++; $rand_image[$x] = "shared/image02.jpg";
$x++; $rand_image[$x] = "shared/image03.jpg";
$x++; $rand_image[$x] = "shared/image04.jpg";
/* Randomly select image to encrypt and use as session variable */
function random_image() {
global $rand_image;
srand ((double) microtime() * 1000000);
print $rand_image[rand(1,sizeof($rand_image))]; }
/* Encryption function for random image */
$hash = md5(uniqid(microtime($rand_image),1));
}
echo $hash;
?>
[end snippit]
Hope that helps some...
Jas


Ryan A wrote:

Hi,
I am making a personal project like so:

I enter something in the text box (eg. "PHP REALLLLLLY ROCKS!!!")
then the program checks if that string already exists in the database, if
no, then it should enter it into the database and also generate a "key"
This key can be given to pals and they can read the "secret message"

Key:
Key should first be 1-1000 then a-z then A-Z then axxx (eg: a001, the xxx
will always be numbers) once it reaches 999 it should become Axxx then b
then B etc after a,A,b,B are done it should go for aaxx,AAxx etc always 4
characters

A few questions:
1.Looking at the above (database part) I figured that doing this via a mysql
database would be better rather than a text database...do you agree?

2.I was thinking of making the "key" field a primary key and unique and
indexed....right?

3.The way I see it theres 3 sql statements that need to be run, a) connect
and see if string exists b)read the last key c)write to the
database...anyway to break the above to 2 statements or am I following this
wrong?

4. Logic for the key, I am coming up with crummy logic to make the "key",
basically a block of code for 1-1000,another block for a-z another block for
A-Z etc...... any ideas,links,URLs or code snippets off the top of your head
would be greatly appreciated.


Thanks in advance.


Cheers,
-Ryan

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to