在select下拉列表中对用户输入进行消毒,而在哪里端点。

发布于 2025-01-24 01:39:05 字数 2359 浏览 1 评论 0原文

当通过jQuery Ajax发布输入到另一个脚本以最终使用Curl将帖子请求发送到端点时,我将如何从选择的下拉列表中清除用户输入?在这种情况下,urlencode是否足够,因为我没有直接将其插入任何数据库,因此,我将这些数据发送到的端点显然会插入数据库中,但它是第三方app app

view.php

function edit_data_title() {
    var lead_id = $("#LeadID").val();
    var title = $(".title option:selected").val();
    var agent_full_name = $("#agent_full_name").val();
    if (confirm('Are you sure you want to update the Title of this lead?')) {
        $.ajax({
            url: "endpoint.php",
            method: "POST",
            data: {
                lead_id: lead_id,
                title: title,
                agent_full_name: agent_full_name
            },
            dataType: "text",
            success: function(data) {
                //alert(data);
                $('#title_readonly').hide();
                $('#title_cancel').hide();
                $('#title_edit_input').hide();
                $('#title_edit_button').show();
                $("#update_lead_title_result").html(data);
                $('#update_lead_title_result').show();
                $('#title').prop('selectedIndex', 0);
            }
        });
    } else {
        alert('Lead title update cancelled');
        $('#title').prop('selectedIndex', 0);
    }
}

<select name="title" id="title" class="title" onchange="edit_data_title();">
   <option value="">Select an option</option>
   <option value="Dr.">Dr.</option>
   <option value="Hon.">Hon.</option>
   <option value="Mr.">Mr.</option>
   <option value="Mrs.">Mrs.</option>
   <option value="Ms.">Ms.</option>
   <option value="Prof.">Prof.</option>
   <option value="Rev.">Rev.</option>
   <option value="Other">Other</option>
</select>

endpoint.php

$title = $_POST['title'];

$curl_url = "https://endpoint101.com?title=$title";
  $ch = curl_init();
  curl_setopt($ch,CURLOPT_URL, $curl_url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_VERBOSE, 0);
  $curl_result = curl_exec($ch);
  $curl_info = curl_getinfo($ch);
  $curl_info = json_encode($curl_info);
  curl_close($ch); 

How would I go about sanitizing user input from my select drop-downs, when posting the input via Jquery AJAX to another script to finally sending a post request to an endpoint using curl? Would urlencode in this case be sufficient as I am not inserting this into any database directly, well the endpoint I am sending this data to will obviously insert into a database but its a 3rd party app

view.php

function edit_data_title() {
    var lead_id = $("#LeadID").val();
    var title = $(".title option:selected").val();
    var agent_full_name = $("#agent_full_name").val();
    if (confirm('Are you sure you want to update the Title of this lead?')) {
        $.ajax({
            url: "endpoint.php",
            method: "POST",
            data: {
                lead_id: lead_id,
                title: title,
                agent_full_name: agent_full_name
            },
            dataType: "text",
            success: function(data) {
                //alert(data);
                $('#title_readonly').hide();
                $('#title_cancel').hide();
                $('#title_edit_input').hide();
                $('#title_edit_button').show();
                $("#update_lead_title_result").html(data);
                $('#update_lead_title_result').show();
                $('#title').prop('selectedIndex', 0);
            }
        });
    } else {
        alert('Lead title update cancelled');
        $('#title').prop('selectedIndex', 0);
    }
}

<select name="title" id="title" class="title" onchange="edit_data_title();">
   <option value="">Select an option</option>
   <option value="Dr.">Dr.</option>
   <option value="Hon.">Hon.</option>
   <option value="Mr.">Mr.</option>
   <option value="Mrs.">Mrs.</option>
   <option value="Ms.">Ms.</option>
   <option value="Prof.">Prof.</option>
   <option value="Rev.">Rev.</option>
   <option value="Other">Other</option>
</select>

endpoint.php

$title = $_POST['title'];

$curl_url = "https://endpoint101.com?title=$title";
  $ch = curl_init();
  curl_setopt($ch,CURLOPT_URL, $curl_url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_VERBOSE, 0);
  $curl_result = curl_exec($ch);
  $curl_info = curl_getinfo($ch);
  $curl_info = json_encode($curl_info);
  curl_close($ch); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东京女 2025-01-31 01:39:05

如果$ title值匹配可用的选项之一,则应检查服务器端。

这是我从问题中给出的输入中推测的唯一条件。

https://www.php.net/manual/manual/en/function。 in-array.php

$allowed_options = ['','Dr.','Hon.','Mr.','Mrs.','Ms.','Prof.','Rev.','Other'];

//if $title value doesn't match any of the allowed options, exits the script
if (!in_array( $title, $allowed_options, true))
  exit;

You should check server side if the $title value matches one of the options available.

That's the only condition I could speculate from the input given in your question.

https://www.php.net/manual/en/function.in-array.php

$allowed_options = ['','Dr.','Hon.','Mr.','Mrs.','Ms.','Prof.','Rev.','Other'];

//if $title value doesn't match any of the allowed options, exits the script
if (!in_array( $title, $allowed_options, true))
  exit;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文