所以我已经管理了如何解码和编码,这是通过 2 个函数完成的。所以这里是例子
http://goldextra.com/b/id_color.php
如果您输入一个单词,它将被编码,如结果页面所示。因此,如果输入 = testword ,则 url 将是http://goldextra.com/b/balloony.php?name=testword
问题是,我希望url看起来像这样 http://goldextra.com/b/balloony.php?name=k484z52646w5i474 (当然网站本身不应该显示加密,而是这个词)
我如何更改我现在拥有的代码,我是否必须更改表单站点或结果站点中的代码?
表格代码
<form action="balloony.php" class="sign-up" method="get" class="sign-up">
<h1 class="sign-up-title">Whats the word?</h1>
<input type="text" class="sign-up-input" placeholder="Enter your baloony" name="name" autofocus>
<input type="submit" value="baloony it!" class="sign-up-button">
结果网站
<?php
function encode($string,$key) {
$key = sha1($key);
$strLen = strlen($string);
$keyLen = strlen($key);
for ($i = 0; $i < $strLen; $i++) {
$ordStr = ord(substr($string,$i,1));
if ($j == $keyLen) { $j = 0; }
$ordKey = ord(substr($key,$j,1));
$j++;
$hash .= strrev(base_convert(dechex($ordStr + $ordKey),16,36));
}
return $hash;
}
function decode($string,$key) {
$key = sha1($key);
$strLen = strlen($string);
$keyLen = strlen($key);
for ($i = 0; $i < $strLen; $i+=2) {
$ordStr = hexdec(base_convert(strrev(substr($string,$i,2)),36,16));
if ($j == $keyLen) { $j = 0; }
$ordKey = ord(substr($key,$j,1));
$j++;
$hash .= chr($ordStr - $ordKey);
}
return $hash;
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo htmlspecialchars($_GET["name"]) . '!'; ?></title>
<style type="text/css">
.BIG {
font-size: 250px;
font-weight: bold;
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
text-align: center;
}
</style>
</head>
<body class="BIG">
<?php
$name = htmlspecialchars($_GET['name']);
$urlENC = encode( $name ,"whateverkey");
$urlDEC = decode( $urlENC ,"whateverkey");
echo htmlspecialchars($_GET["url"]) . '';
echo $urlENC; ?>
<br />
<? echo $urlDEC; ?>