我想使用这个,因为我必须维护一个会话。我尝试过这种方式,但是当页面打开时,函数正在立即执行:
<a onclick="myfunction();">text</a>
功能:
function myfunction()
{
<?php
header("location: page.php");
exit;
?>
}
我也尝试了表单和按钮,但不工作。
HTML
<a href="redirect.php">text</a>
redirect.php
<?php
session_start();
if($_SESSION['smth']){
header("location: page.php");
} else {
// to do what you want
}
?>