note 71821 deleted from function.md5 by nlopess
| From: | nlopess@php.net | Date: | Mon, 18 Dec 2006 10:52:01 +0000 |
| Subject: | note 71821 deleted from function.md5 by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-120720@lists.php.net to get a copy of this message | ||
Note Submitter: gnif at spacevs dot com
----
I was looking for a simple way to secure a script from abuse when the idea of signing the get
request hit me...
<?PHP
$text = $_GET["text"];
$key = "MyExampleSignKey";
if (md5($text . $key) != $_GET['md5'])
die("Unauthorized Use");
echo "Authorized Use :D";
?>
This means that parameters can be passed with a signature of the value and the hidden key. I wanted
this for a small image generation script that could be put into a <img src=""> tag.
It could also be useful for simple protection from malicious urls since the client doesnt know the
key to hash the data with and the script will fail on modification.
<?PHP
$page = $_GET["include"];
$key = "MyExampleSignKey";
if (md5($text . $key) != $_GET['md5'])
die("Unauthorized Use");
include($page);
?>
A small function could help in production of links...
<?PHP
function signedURL($key, $page, $link) {
return "<a href=\"index.php?page=$page\">$link</a>";
}
?>