How to reduce GET request to the desired settings?

Good evening! Please help in the next question. I have the following query:
http://pagination.loc/getData.php?draw=2&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=1&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=2&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B3%5D%5Bdata%5D=3&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=4&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=5&columns%5B5%5D%5Bname%5D=&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=25&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1582036792375


You need to be, which would have removed the parameters column search, and would remain such:
http://pagination.loc/getData.php?draw=1&start=1&length=4&_=1582036169296
April 7th 20 at 15:43
3 answers
April 7th 20 at 15:49
April 7th 20 at 15:45
Solution
Here it is:
<?php

$url = "http://pagination.loc/getData.php?draw=2&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true".
"&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false".
"&columns%5B1%5D%5Bdata%5D=1&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true".
"&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=2&columns%5B2%5D%5Bname%5D=".
"&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false".
"&columns%5B3%5D%5Bdata%5D=3&columns%5B3%5D%5Bname%5D=&columns%5B3%5D%5Bsearchable%5D=true&columns%5B3%5D%5Borderable%5D=true&columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=".
"&columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B4%5D%5Bdata%5D=4&columns%5B4%5D%5Bname%5D=&columns%5B4%5D%5Bsearchable%5D=true&columns%5B4%5D%5Borderable%5D=true".
"&columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B5%5D%5Bdata%5D=5&columns%5B5%5D%5Bname%5D=".
"&columns%5B5%5D%5Bsearchable%5D=true&columns%5B5%5D%5Borderable%5D=true&columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false".
"&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=25&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1582036792375";
$url = urldecode($url);
parse_str(parse_url($url, PHP_URL_QUERY), $arr);
$url = str_replace(parse_url($url, PHP_URL_QUERY), http_build_query(array_intersect_key($arr, array_flip(array("_","draw","start","length")))), $url);
echo($url);
Super! - lennie.Beatty commented on April 7th 20 at 15:48
just please tell me how to apply your code in the file where the query is formed like this: https://github.com/codexworld/Datatables-Server-si... - lennie.Beatty commented on April 7th 20 at 15:51
In the class there is no HTTP request, no compile URL, nothing.
Only SQL queries to the database. - Fay commented on April 7th 20 at 15:54
@Manuela_Spencer93, I needed it to handle:
5e4c2ff11c319794664261.png - lennie.Beatty commented on April 7th 20 at 15:57
So this is a request from the browser. It can be hard coded in HTML.-e, and can be generated dynamically via JavaScript.
Although in any case, will have to look for a PHP or JS script in which everything is written.
Hence the conclusion: we need to hire a specialist, tobish programmer... - Fay commented on April 7th 20 at 16:00
Well, or at least to look and then watch the files that have the string "getData.php".
This is to find the script which generated the HTTP request... - Fay commented on April 7th 20 at 16:03
@Manuela_Spencer93, here is the file getData:

<?php
 ini_set('display_errors', 0);
/*
 * DataTables example server-side processing script.
*
 * Please note that this script is intentionally extremely simple to show how
 * server-side processing can be implemented, and probably shouldn't be used as
 * the basis for a large complex system. It is suitable for simple use cases as
 * for learning.
*
 * See <a href="http://datatables.net/usage/server-side">http://datatables.net/usage/server-side</a> for full details on the server-
 * side processing requirements of DataTables.
*
 * @license MIT <a href="http://datatables.net/license_mit">http://datatables.net/license_mit</a>
*/

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Easy set variables
*/

// DB table to use
$table = 'members';

// Table''s primary key
$primaryKey = 'id';

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
 array( 'db' => 'first_name', 'dt' => 0 ),
 array( 'db' => 'last_name', 'dt' => 1 ),
 array( 'db' => 'email', 'dt' => 2 ),
 array( 'db' => 'gender', 'dt' => 3 ),
array(
 'db' => 'created',
 'dt' => 4,
 'formatter' => function( $d, $row ) {
 return date( 'jS M y', strtotime($d));
}
),
array(
 'db' => 'country',
 'dt' => 5,
 'formatter' => function( $d, $row ) {
 return '$'.number_format($d);
}
)
);

// SQL server connection information
$sql_details = array(
 'user' => 'root',
 'pass' => ",
 'db' => 'test',
 'host' => 'localhost'
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * If you just want to use the basic configuration for DataTables with PHP
 * server-side, there is no need to edit below this line.
*/

require( 'ssp.class.php' );

echo json_encode(
 SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
- lennie.Beatty commented on April 7th 20 at 16:06
but index.html:

<!DOCTYPE html>
<html lang="en-us">
the <head>
 <meta charset="utf-8">
 <!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->
 <title> Test</title>
 <meta name="description" content="">
 <meta name="author" content=""> 
 <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
by adding crossorigin="anonymous"></script>
 <script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
 <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css">
 <link rel="stylesheet" type="text/css" media="screen" href="css/style.css"> 
 </head> 
 <body class="">
 <div class="container">
 <table id="example" class="display" style="width:100%">
<thead>
the <tr>
 <th>First name</th>
 <th>Last name</th>
<th>Position</th>
<th>Office</th>
 <th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
the <tr>
 <th>First name</th>
 <th>Last name</th>
<th>Position</th>
<th>Office</th>
 <th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
</div>
</body>
the <script>
 $(document).ready(function() {
 $('#example').DataTable( {
 "processing": true,
 "serverSide": true,
 "ajax": "getData.php"
 } );
} );
</script>
</html>
- lennie.Beatty commented on April 7th 20 at 16:09
That would shorten the request URL, try to change the javascript at the end of the HTML I have:
the <script>
 $(document).ready(function() {
 $('#example').DataTable( {
 "processing": true,
 "serverSide": true,
 "ajax": "getData.php",
 "searching": false,
 "ordering": false,
 } );
} );
</script>

But then the data in the table cannot be sorted (by clicking column headers), and the search won't work. Apparently... - Fay commented on April 7th 20 at 16:12
@Manuela_Spencer93, no, did not help! - lennie.Beatty commented on April 7th 20 at 16:15
Change the HTML option on the"serverSide": false,.
And "searching" and "ordering" - clean, of course, if they are. - Fay commented on April 7th 20 at 16:18
@Manuela_Spencer93, later definitely try! - lennie.Beatty commented on April 7th 20 at 16:21
April 7th 20 at 15:47
If I understand correctly that it is happening inside the script getData.php
Try filter_input_array()

Something like this:
$args = array(
 'draw' => FILTER_SANITIZE_NUMBER_INT,
 'start' => FILTER_SANITIZE_NUMBER_INT,
 'length' => FILTER_SANITIZE_NUMBER_INT,
 '_' => FILTER_SANITIZE_NUMBER_INT,
);

$data = filter_input_array(INPUT_GET, $args);
// in the array will be only these four values

// We can use this to build a new link:
$url = 'http://pagination.loc/getData.php?' . http_build_query($data);

Find more questions by tags PHP