“Cara Memeriksa Metode Permintaan di PHP” Kode Jawaban

Jenis Permintaan Deteksi PHP

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     // Boom baby we a POST method
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
     // We are a GET method
}
Grepper

Metode Pemeriksaan PHP dari Permintaan HTTP

<?php

$method = $_SERVER['REQUEST_METHOD'];

switch ($method) {
  case 'GET':
    //Here Handle GET Request
    echo 'You are using '.$method.' Method';
    break;
  case 'POST':
    //Here Handle POST Request
    echo 'You are using '.$method.' Method';
    break;
  case 'PUT':
    //Here Handle PUT Request
    echo 'You are using '.$method.' Method';
    break;
  case 'PATCH':
    //Here Handle PATCH Request
    echo 'You are using '.$method.' Method';
    break;
  case 'DELETE':
    //Here Handle DELETE Request
    echo 'You are using '.$method.' Method';
    break;
  case 'COPY':
      //Here Handle COPY Request
      echo 'You are using '.$method.' Method';
      break;

  case 'OPTIONS':
      //Here Handle OPTIONS Request
      echo 'You are using '.$method.' Method';
      break;
  case 'LINK':
      //Here Handle LINK Request
      echo 'You are using '.$method.' Method';
      break;
  case 'UNLINK':
      //Here Handle UNLINK Request
      echo 'You are using '.$method.' Method';
      break;
  case 'PURGE':
      //Here Handle PURGE Request
      echo 'You are using '.$method.' Method';
      break;
  case 'LOCK':
      //Here Handle LOCK Request
      echo 'You are using '.$method.' Method';
      break;
  case 'UNLOCK':
      //Here Handle UNLOCK Request
      echo 'You are using '.$method.' Method';
      break;
  case 'PROPFIND':
      //Here Handle PROPFIND Request
      echo 'You are using '.$method.' Method';
      break;
  case 'VIEW':
      //Here Handle VIEW Request
      echo 'You are using '.$method.' Method';
      break;
  Default:
    echo 'You are using '.$method.' Method';
  break;
}


?>
Gifted Goat

Cara Memeriksa Metode Permintaan di PHP

// Check request method in php using super global variable $_SERVER
if(isset($_SERVER['REQUEST_METHOD'])){
	// Now display request method
    echo $_SERVER['REQUEST_METHOD'];
}
Abhay Mishra

Jawaban yang mirip dengan “Cara Memeriksa Metode Permintaan di PHP”

Pertanyaan yang mirip dengan “Cara Memeriksa Metode Permintaan di PHP”

Lebih banyak jawaban terkait untuk “Cara Memeriksa Metode Permintaan di PHP” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya