PHP 多次重定向 [英] PHP multiple redirects
本文介绍了PHP 多次重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有单个变量listing_type"的 $_POST 数组.表单提交到包含以下代码的页面,该页面将它们重定向到另一个页面,其中包含更多依赖于初始选择的表单.有没有更巧妙的方法来做到这一点?它工作正常,但感觉很笨重...
I have a $_POST array with a single variable 'listing_type'. The form submits to a page containing the code below which redirects them to another page with more forms dependent on their initial choice. Is there a slicker way to do this? It works fine but feels clunky...
<?php // listing-type.php
if ((isset($_POST['listing_type'])) && (!empty($_POST['listing_type']))) {
switch($_POST['listing_type']) {
case "1":
$url = "events/new-event.php";
break;
case "2":
$url = "restaurants/new-restaurant.php";
break;
case "3":
$url = "bars/new-bar.php";
break;
case "4":
$url = "attractions/new-attraction.php";
break;
}
header("Location: $url"); // Perform redirect to given new listing page
}
else { // Redirect to homepage if no usuable listing_type data from form
$url = "index.php";
header("Location: $url");
}
推荐答案
很好,除了不需要两次定位调用,也不需要 else :
It's fine except there is no need to have two location calls, and you don't need the else:
$url = "index.php";
if ((isset($_POST['listing_type'])) && (!empty($_POST['listing_type']))) {
// Switch statement
}
header("Location: $url");
这篇关于PHP 多次重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文