【问题标题】:Redirect php page without javascript [duplicate]重定向没有javascript的php页面[重复]
【发布时间】:2015-04-27 12:50:28
【问题描述】:

大家好,有没有什么方法可以在没有 header() 和 java 脚本的情况下重定向页面? php有另外一个可以重定向页面的功能吗?

首页 ...

    <?php
    $item_query=mysql_query("SELECT * FROM items ") or die(mysql_error());
    while($run_item=mysql_fetch_array($item_query))
    {
        $itemid=$run_item['item_id'];
        $name=$run_item['productname'];
        echo "<br/>";
        echo "<a href='product.php?product=$userid'>$username</a>";
    }
?>

第二页...

if(isset($_GET['product'] ) && !empty($_GET['product'])){
    $itemid=$_GET['product'];
}else{
    $itemid= $_SESSION['item_id'];
}
$Item_query=mysql_query("SELECT * FROM item WHERE item_id=$itemid") or die( mysql_error());
while($run_item= mysql_fetch_array($mem_query)){
            $meid=$run_item['item_id'];
            $name=$run_item['name'];
}
    $my_id=$_SESSION['item_id'];
    echo '<h3> Your Name: '.$name."<br/>ID: ".$meid.'</h3>';
            $sendquery=mysql_query("SELECT fid FROM order WHERE inorder= $itemid AND userid= $my_id ")or die (mysql_error());
                    echo "<a href='actions.php?action=send&product=$itemid'> ordered </a>";

第三页... 当我点击订购的链接时,我的第二页会来到这里

$action=$_GET['action'];
$itemid=$_GET['item'];
$my_id=$_SESSION['item_id'];
if($action=='send'){    
    mysql_query("INSERT INTO order VALUES ('','$my_id','$userid')");
}
    header('location:items.php?item=$itemid');

//header('location:items.php?item=$itemid');---->这里出现错误

“where 子句”中的未知列“$item” 当我点击已订购的链接时出现此错误。

【问题讨论】:

  • 为什么不使用 header()?非常适合这份工作
  • 您为什么不想使用正确的工具来完成这项工作?
  • 为什么 PHP 应该有另一个工具来做同样的标题??
  • 因为 header() 给了我错误。它不适用于 $_Get 变量
  • 请分享您的 header() 代码,也许我们可以找出问题所在。

标签: javascript php redirect header


【解决方案1】:

您可以使用元刷新标签。没有 php,不需要 javascript。像这样的语法..

<META http-equiv="refresh" content="10;URL=http://www.google.com/">

10 秒,URL 是要重定向的页面。

【讨论】:

    【解决方案2】:

    你可以使用 header()。

    例子:

    header("Location: /newpage.php");
    

    你也可以使用元:

    <META http-equiv="refresh" content="0;URL=http://www.yoursite.com/">
    

    【讨论】:

      【解决方案3】:

      有一个可以重定向的元标记,但你应该使用 header(),

      &lt;META HTTP-EQUIV="Refresh" Content="0; URL=page.php"&gt;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-07
        • 2013-11-13
        • 2013-11-18
        • 2012-12-09
        • 2018-02-04
        • 1970-01-01
        • 1970-01-01
        • 2020-12-02
        相关资源
        最近更新 更多