如果[关闭],我如何使用 PHP 自动更改页面

Posted

技术标签:

【中文标题】如果[关闭],我如何使用 PHP 自动更改页面【英文标题】:How can I use PHP to automatically change the page if [closed] 【发布时间】:2012-04-29 19:24:22 【问题描述】:

...if 语句的条件是否满足?

如果满足某些条件,我有一些代码可以将数据添加到数据库,添加数据后我希望页面重定向到另一个页面?我该怎么做?

【问题讨论】:

header('location: /page2.php'); 【参考方案1】:

使用 if-else 条件。你可以使用 PHP 的 header() 。

if(/* Your conditions */)
// redirect if fulfilled
header("Location:nxtpage.php");
else
//some another operation you want

【讨论】:

【参考方案2】:

你应该使用 header php 函数

<?php 

  //some conditions

  header("Location: http://www.example.com/");

?>

【讨论】:

【参考方案3】:

试试这个代码

 $query ="insert into test values (1,'test')";

if(mysql_query($query) == true)

  header('location:index.php');
  exit();

else

  echo " insert failed";

【讨论】:

【参考方案4】:

试试PHP Header:

header('位置:http://www.example.com/');

【讨论】:

以上是关于如果[关闭],我如何使用 PHP 自动更改页面的主要内容,如果未能解决你的问题,请参考以下文章