Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

php - Pass time/date time URL for API [WORDPRESS]

I would need to pass to URL a date in order to extract all the records from my table since that date. Problem is, I don't know the correct way to pass a date via URL.

In place of "HEREHERE" what should I put to pass a date?

register_rest_route('cp/v1', '/logcaptiveportal/data/HEREHERE', [
    'methods' => 'GET',
    'callback' => 'get_data_log',
    'permission_callback' => function($request){
        return is_user_logged_in();},
]);

And what does it use to extract it?

function get_data_log($data){
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysqli_select_db($conn, DB_NAME);
global $wpdb;
$pr = $wpdb->prefix;
$response = array();
$datalog = $data['id'];
/*Estraggo durata di navigazione*/
$getusermeta = "SELECT * FROM " . $pr . "logcaptiveportal WHERE Orario LIKE '%$datalog%'";
$result = $conn->query($getusermeta);
if ($result->num_rows > 0) 
{
    // output data of each row
    while($row = $result->fetch_assoc()) 
    {
        $response[$i]['User ID'] = $row["user_id"];
        $response[$i]['Nickname'] = $row["nickname"];
        $response[$i]['Pagina visitata'] = $row["pagina_visitata"];
        $response[$i]['Mac-Address'] = $row["user_mac"];
        $response[$i]['Orario'] = $row["Orario"];
        $response[$i]['link'] = $_SERVER['REQUEST_URI'];
        $i++;
    }
    echo json_encode($response,JSON_PRETTY_PRINT);
}
else 
    echo "Non esiste nessun log con il/la seguente orario/data: ".$datalog."";

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...