【问题标题】:How can I redirect to the same page with $_GET parameters in URL如何在 URL 中使用 $_GET 参数重定向到同一页面
【发布时间】:2018-04-16 16:44:58
【问题描述】:

我有一个关于重定向的问题。 我在我的 URL 中放了一些参数,这样我就可以使用 $_GET 将它们取出,然后将它们放入一个变量中。 现在,当我填写错误的表格时,我会被重定向,但所有参数都丢失了,它们不再在变量中了。 有没有办法可以用相同的参数重定向到同一个页面?

带有参数的网址: http://localhost:8888/WD2/Week6/Project/flight_bestel.php?stoelnr=5&prijs=99.00&bestemming=Spanje&aankomst=%20Barcelona%20Airport

重定向后的网址: http://localhost:8888/WD2/Week6/Project/flight_bestel.php

谢谢

<?php
session_start();
include_once ("scripts/config.php");
include_once ("scripts/api.php");

$stoelNr = $_GET['stoelnr'];
$prijs = $_GET['prijs'];
$bestemming = $_GET['bestemming'];
$aankomst = $_GET['aankomst'];


if($_SERVER['REQUEST_METHOD'] === 'POST') {

}else{};

?>

<?php require_once( 'views/shared/_header.inc' ); ?>
<body>
<header>
    <?php include( 'views/shared/_nav.inc' ); ?>
</header>

<main>

    <div id="contents" class="container">
        <section id="summary">
        
            <form action= "<?php echo $_SERVER['PHP_SELF']; ?>"     method="post" class="form-horizontal">
            
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-info"     name="bestel">Bestel nu!</button>
                    </div>
                </div>
            </form>

        </section>
    </div>
</main>
<?php require_once( 'views/shared/_footer.inc' ); ?>

【问题讨论】:

标签: php html api redirect get


【解决方案1】:

所以你的问题变成了......“如何重建原始 URL 作为我的表单的操作”?

一种方法是获取查询字符串并使用它来重建您的表单“动作”。

有点像... 获取您的原始查询字符串

$query_string = '?'.$_SERVER['QUERY_STRING'];

并将其附加到您的表单操作

<form action= "<?php echo $_SERVER['PHP_SELF'] .$query_string; ?>" method="post" class="form-horizontal">

这应该会让你对你正在研究的那部分谜题有所了解。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多