random key generator with validity check
<p>What if i want to add an option to my website like API !</p>

<p>when anyone call <code>my.site.dot.com/api.php?id=name</code> it will add the <code>name</code> to my database</p>

<p>but i'm getting a lot of spam entries so i've been thinking about using a key !</p>

<p>so it would be like <code>my.site.dot.com/api.php?id=name&amp;key=MMSDJJSHHHAG</code>
if the key is right then it <code>echo "passed";</code> and if wrong then <code>echo "stopped";</code></p>

<p><strong>Now my question</strong>
I want any function that can generate random key either of letters or numbers or both whatever.</p>

<p>but the bottom line is it must be also able to know its keys WHY ! cause when someone call <code>my.site.dot.com/api.php?id=name&amp;key=MMSDJJSHHHAG</code> it become able  to know that <code>MMSDJJSHHHAG</code> is valid key.</p>

<p><code>my.site.dot.com/api.php?id=name&amp;key=MMSDJJSHHHAG</code></p>

<pre><code>&lt;?PHP
echo $id; //name
echo $key; //MMSDJJSHHHAG

if ( key is valid ) {
echo "passed";
} else {
echo "stopped";
}
?&gt;
</code></pre>

<p>I know there some other ideas like every time i generate new key to store it in text file or in database table...etc and that are good ideas but i'll generate it upon viewing an page so someone can makes billions of refresh making site down :(</p>

<p>I'm thinking of math equations !! any help about this idea ~ thanks a lot</p>
