douliao5942 2017-04-05 08:36
浏览 125
已采纳

php如何只允许url中的特殊参数或重定向到其他参数

I need help to write function which help me clean out any unusual ( not allow in array list) then redirect to right url

eg my original is /modules.php?aaa=111&bbb=2

the var aaa and bbb is alow using on urls ,

if some one ads other var to url incase you mess up or want to overhead the server they will redirect back to original one.. but cut all invalid param out.

eg: /modules.php?aaa=111&notgood=999&bbb=2

will redirect back to

modules.php?aaa=111&bbb=2

the &notgood=999 or any other will be strip out..

$goodvar = array("aaa","bbb");
$requesturi = $_SERVER['REQUEST_URI'];

if   /// Need help : if other query not in the list of good var will be clean out of requesturi to build NEWrequesturi
{
    header("Location: ".$NEWrequesturi,TRUE,301); exit; die(); 
}

thanks very much kind regards

  • 写回答

1条回答 默认 最新

  • douqi3195 2017-04-05 08:57
    关注
    <?php
    
    $good_var = ["aaa", "bbb"];
    $query_params = explode(".php?", $_SERVER['REQUEST_URI'])[1];
    $all_query_data = explode("&", $query_params);
    $data_set = [];
    foreach ($all_query_data as $query_value) {
        $param = explode("=", $query_value);
        $data_set[$param[0]] = $param[1];
    }
    $paased_args = array_keys($data_set);
    if (empty(array_diff($paased_args, $good_var))) {
        echo "Url is good";
        // do whatever you want when url is good
    } else {
        echo "Url tempered";
        //url has been tempered do as you wish
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.