简体   繁体   English

API查询失败将API密码输出到用户前端

[英]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. 用户输入内容后,将根据输入内容查询API(JSON)。 Every now and then the API query fails and outputs the query URL. API查询有时会失败并输出查询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. 查询URL包含一个密码,该密码当然是秘密的。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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