我正在使用php创建一个页面,我来到了一个点,我有一个if有两个条件,我需要如果条件为真,按钮将我发送到另一个页面,这可能吗? 我现在有这个代码:
按钮:
<form method="post">
<input type="submit" name="submit" class="buttonStyle" />
</form>
PHP脚本:
<?php
$homepage = "/site/nelson.php";
$currentpage = $_SERVER['REQUEST_URI'];
if(isset($_POST['submit']) && $homepage==$currentpage)
{
#Here should be the redirect
}
?>
希望有人可以帮助我:) 谢谢!
编辑:找到解决方案,谢谢(!!!!!!!!!!!!)给所有人!答案 0 :(得分:3)
正如其他答案所示,您应该使用header功能。您还可以在标头中设置延迟,以便在重定向之前等待几秒钟:
header("Refresh: 5;url=yoururl.com");
如果它不起作用,那么你应该看看this answer!
答案 1 :(得分:1)
header("Location: http://my.domain.com/other_page");
请注意,要实现此功能,可能无法将HTML发送到客户端。假设您的代码片段在同一个文件中,这意味着PHP块应该放在HTML块之前。
答案 2 :(得分:0)
<?php
$homepage = "/site/nelson.php";
$currentpage = $_SERVER['REQUEST_URI'];
if(isset($_POST['submit']) && $homepage==$currentpage) <--- the php script
{
header('Location: http://www.example.com/');
}
?>
<form method="post">
<input type="submit" name="submit" class="buttonStyle" /> <---the button
</form>