我有一些PHP,我必须添加到我的页面几次,而不是只是粘贴它多次我想把它全部变成一个PHP变量。我一直在搜索,但不认为我知道正确的术语来寻求实现这一点。
以下是我试图变成1个变量的内容:
session_start();
$time = time();
$hash = md5($key . $time);
$str = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url = str_replace("0239", "738", $str);
header("Location: http://google.com");
exit;
答案 0 :(得分:0)
不要把它变成变量,而是变成一个函数。
function functionName($key) {
session_start();
$time = time();
$hash = md5($key . $time);
$str = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url = str_replace("0239", "738", $str);
header("Location: http://google.com");
exit;
}
现在你可以在任何地方进行代码调用
funcitonName($key);
执行你的代码。