我对php中的重定向有疑问
我有2页
-索引的第一页
-流程编辑或编辑的第二页php
我的问题是…
如果我点击edit,他肯定在edit.php中,如果我点击了edit.php中的save
如果我的重定向代码header('location:index.php');
如何返回或重定向到索引,但仍处于逻辑状态2或$_POST['select']=='2'
这是我的代码:
<form action='' methode='post'>
<select name='select'>
<option value='1'>example1</option>
<option value='2'>example2</option>
</select>
</form>
<?php
if($_POST['select']=='1')
{
echo"<a href='?page=edit&id=$r[id]'>Edit</a>";
}
elseif($_POST['select']=='2')
{
echo"<a href='?page=edit&id=$r[id]'>Edit</a>";
}
else
{
echo"please select";
}
?>
Header,如果您有它们,必须是输出到浏览器的第一个东西。这包括在打开<?php
标签之前不具有任何空白。
如果你想对要发送的标头进行比较,那么你可以,但这应该是你在$_POST
变量上进行比较后的第一件事。
另外,您需要在Location标头中使用一个绝对地址。
例如;
<?php
if($_POST['select']=='1')
{
header('Location: http://yoursite.com/index.php');
}
elseif($_POST['select']=='2')
{
echo"<a href='?page=edit&id={$r[id]}'>Edit</a>";
}
else
{
echo"please select";
}
?>
<form action='edit.php' method='post'>
<select name='select'>
<option value='1'>example1</option>
<option value='2'>example2</option>
</select>
</form>
希望这能有所帮助!