How can in_array work while fetching values from external URL using PHP

Andy

I have following code which contains some keys and when someone want to get some info from my server they send that API param with the URL and then it validates with my API keys stored and returns output.

$get_api = $_GET['api'];
$api = array('api_key1','api_key2','api_key3','api_key4');

if(in_array($get_api,$api, true)){
   echo "Found";
} else{
   echo "Not found";
}

When someone pass following API param, they will see output as found when URL is following:

https://www.example.com/index.php?api=api_key1

However I have several servers where I have to host these API Keys. So I cannot manually go and add API keys every time when I have to add one. So I did the following thing. I tried to host API Keys on one server and every other server would look in that file and if found it would return found.

The code for that was:

API Hosted Code: (HTML)

'api_key1','api_key2','api_key3','api_key4'

Code which request API Keys: (PHP)

$get_api = $_GET['api'];
$fetch_keys = file_get_contents("https://www.example.com/path-to-keys.html");
$api = array($fetch_keys);  // fetching and putting that in array

if(in_array($get_api,$api, true)){
   echo "Found";
} else{
   echo "Not found";
}

However, it is not working. It is returning internal error. Please can anyone guide how can I solve it or is their any better way to do it. Thanks

Mohammed Azar

Try $api= explode (',', $fetch_keys);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Mysql

Actions links not working while fetching data from database using ajax in php

From Dev

Redundant values while fetching distinct values from column after joins

From Dev

How to avoid multiple try catch for undefined values (by using if/else or some other way) while fetching border values from Google Spreadsheet?

From Dev

Error in fetching multidimensional array from database using php

From Dev

Fetching values from sql 2005 using vbscript

From Dev

How can I get the session values from an external.js by using Struts2 jQuery

From Dev

html Table taking extra blank values while fetching the row from mysql using php

From Dev

getting incorrect values while fetching values from an array

From Dev

How can I resize an image from URL using PHP?

From Dev

Error while using mysql_num_rows() for fetching data from sql tables using php while using foreign key contraint

From Dev

How can I get in_array() to work with multidimensional arrays?

From Dev

Notice: Undefined offset: 2 ,while fetching the data from csv using php

From Dev

Can not avoid duplicate data while fetching from database using PHP and MySQL

From Dev

fetching result using php array_values in different php version

From Dev

Fetching a value from a PHP array

From Dev

Encountering android.os.NetworkOnMainThreadException while fetching data from a PHP script using Okhttp

From Dev

PHP search array column for 2 values using in_array()

From Dev

How to access values from XML URL directly using PHP

From Dev

How does looping though a PHP array using While() work?

From Dev

Error while calling External REST URL from netsuite using token

From Dev

How can I refactor this code for fetching Mongo Data from an Array?

From Dev

PHP in_array search using values from an array

From Dev

Fetching URL from a redirected target using Python

From Dev

How can I match an exact numeric string using in_array?

From Dev

Missing one value while using in_array in php

From Dev

Php: How to limit the number of rows returned while fetching values from a text file?

From Dev

Using the data of a picker for fetching values would not work

From Dev

While fetching 4000 or more values from a database (postgresql) it is not possible to filter the elements. (using Reactive streams)

From Dev

How can I efficiently work with arrays from php while loop?

Related Related

  1. 1

    Actions links not working while fetching data from database using ajax in php

  2. 2

    Redundant values while fetching distinct values from column after joins

  3. 3

    How to avoid multiple try catch for undefined values (by using if/else or some other way) while fetching border values from Google Spreadsheet?

  4. 4

    Error in fetching multidimensional array from database using php

  5. 5

    Fetching values from sql 2005 using vbscript

  6. 6

    How can I get the session values from an external.js by using Struts2 jQuery

  7. 7

    html Table taking extra blank values while fetching the row from mysql using php

  8. 8

    getting incorrect values while fetching values from an array

  9. 9

    How can I resize an image from URL using PHP?

  10. 10

    Error while using mysql_num_rows() for fetching data from sql tables using php while using foreign key contraint

  11. 11

    How can I get in_array() to work with multidimensional arrays?

  12. 12

    Notice: Undefined offset: 2 ,while fetching the data from csv using php

  13. 13

    Can not avoid duplicate data while fetching from database using PHP and MySQL

  14. 14

    fetching result using php array_values in different php version

  15. 15

    Fetching a value from a PHP array

  16. 16

    Encountering android.os.NetworkOnMainThreadException while fetching data from a PHP script using Okhttp

  17. 17

    PHP search array column for 2 values using in_array()

  18. 18

    How to access values from XML URL directly using PHP

  19. 19

    How does looping though a PHP array using While() work?

  20. 20

    Error while calling External REST URL from netsuite using token

  21. 21

    How can I refactor this code for fetching Mongo Data from an Array?

  22. 22

    PHP in_array search using values from an array

  23. 23

    Fetching URL from a redirected target using Python

  24. 24

    How can I match an exact numeric string using in_array?

  25. 25

    Missing one value while using in_array in php

  26. 26

    Php: How to limit the number of rows returned while fetching values from a text file?

  27. 27

    Using the data of a picker for fetching values would not work

  28. 28

    While fetching 4000 or more values from a database (postgresql) it is not possible to filter the elements. (using Reactive streams)

  29. 29

    How can I efficiently work with arrays from php while loop?

HotTag

Archive