假设我有如下代码:
<td><a href="view_edit_form.php?id=<?php echo md5($row[0]);?>">Edit</a></td>
在页面中,view_edit_form.php
我使用此代码获取 id$ID = $_GET['id'];
问题
id
如果我md5
喜欢这样,我无法获得。请帮助我,谢谢。
如果您只是想掩盖 id,我建议您使用两个代码,它们可以放在您的 url 之前和之后。
$before_code = "8292273";
$after_code = "9388347";
如果你在你的 id 中使用字符,那么混合一些
我假设 $row[0] 是你的 id
<a href="view_edit_form.php?id=<?php echo $before_code.$row[0].$after_code; ?>">
Edit
</a>
如果您将之前和之后的代码设置为设定的长度,您可以随机更改它们并使用substr
从开头和结尾删除设定的字符数以获取您的 id。
如果您使用设置代码,那么您可以使用str_replace
或preg_replace
删除留下您 ID 的代码。
只要您将代码留给自己,大多数人将无法找到该 ID,除非它是那个人的 ID,并且他们已经知道它是什么......这会浪费时间......
You can't get the md5
hash unless it is stored elsewhere against an $ID
and retrieved. (md5
is a one-way hashing algorithm: See here).
Your source.php probably needs to look like:
<td><a href="view_edit_form.php?id=<?php echo $row['id_hash'];?>">Edit</a></td>
Your rendered HTML may look like:
<td><a href="view_edit_form.php?id=79054025255fb1a26e4bc422aef54eb4">Edit</a></td>
In your source.php
file AND view_edit_form.php
, you need to make a call to your database (This is more often than not stored in a database) to retrieve the hash (or $ID
) based on the the md5
hash in question.
You may be better off using a different hashing algorithm, but md5 is usually acceptable for basic security/obfuscation - but NOT for encrypted passwords these days. It's pretty much dependent on what you mean by security.
Hope this helps.
使用mcrypt_encrypt()
和mcrypt_decrypt()
加密和解密数据。