Create PHP API และวิธีเรียกใช้งาน PHP API

3 ต.ค. 2023 , 902 Views   , หมวดหมู่ โค๊ดดิ้ง   , ป้ายกำกับ:, , ,


Create API

Basic Authorization

Bearer Authorization

ปกติแล้ว PHP จะไม่สามารถรับค่า Authorization แบบ Bearer ได้โดยตรง เพื่อความปลอดภัย แต่เราสามารถกำหนดค่าที่ .htaccess เพื่อรีไดเร็คค่านี้ไปยัง PHP ได้

และรับค่าเป็น

การรับค่า Authorization ของ PHP ยังมีอีกวิธีที่สามารถรับได้ ถ้า Server รองรับ คือการรับค่าด้วยฟังก์ชั่น apache_request_headers() ดังตัวอย่าง

ตัวอย่าง Bearer Authorization 🔥

Call API

แบบทำเป็น function

ไม่ทำเป็น function (Authorization: Basic)

หรือ https://www.gavsblog.com/blog/how-to-use-basic-authentication-with-php-curl 🔥

หรือ

Authorization: Bearer

 

ดูเพิ่มเติม

https://www.goragod.com/knowledge/การพิสูจน์ตัวตนบน_php_http_authentication_with_php.html 🔥

https://developer.okta.com/blog/2020/01/15/protecting-a-php-api-with-oauth 🔥

https://www.codeofaninja.com/rest-api-authentication-example-php-jwt-tutorial/

https://monkeywebstudio.com/basic-restful-web-api-phpmysql/

https://www.discussdesk.com/how-to-call-api-using-http-basic-authentication-with-php-curl.htm

https://metamug.com/article/api-integration/consuming-rest-api-in-php.html 🔥

https://www.gavsblog.com/blog/how-to-use-basic-authentication-with-php-curl 🔥


ป้ายกำกับ:, , ,