简体   繁体   中英

Failing API query outputs API password to the user frontend

I have a website with a user input. After the user inputs something, an API (JSON) is queried based on the input. Every now and then the API query fails and outputs the query URL.

 file_get_contents(http://...id=...password=...&input=...): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /www/htdocs/....php

The query URL contains a password which is, of course, secret. How can I prevent the page to output the failed request?

Best Benjamin

You should have error reporting off for a production server, but as a quick fix you can use the error suppression symbol @ :

$resp = @file_get_contents(...);

Obviously you will still need to handle a failed call by checking the return value:

if($resp==false)//failed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM