doujue1246 2018-11-22 11:23
浏览 110
已采纳

如何查看我的网站页面PHP的来源是什么

I want to know if Its possible to see what resource is calling my website page (PHP file).
I have created an API PHP page which handles JSON POST data and saves it to the DB.
Now I would like to know what resource is calling my PHP page.
As example I'm using POSTMAN to post data to my page.
Is it possible to see that a call came from postman?.
Is that possible to get that information in PHP?

  • 写回答

1条回答 默认 最新

  • doulei6330 2018-11-22 21:31
    关注

    You can know some things about the request, for example:

    1) IP address:

    // Read the IP from who is really making the request (a user or a proxy)
    $ipAddress = $_SERVER['REMOTE_ADDR'];
    // Read the IP that the proxy is telling us making the request.
    $ipAddress = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
    

    If the source of the request is behind a proxy, $_SERVER['REMOTE_ADDR'] will have the IP of the proxy, so you can check the HTTP_X_FORWARDED_FOR header but can be easily spoofed, unless you have control of the proxy or is a trusted proxy.

    2) User Agent:

    // Using global $_SERVER
    $userAgent = $_SERVER['HTTP_USER_AGENT'];
    
    // Using get_browser function you can get an array with the information
    $arrayBrowserInfo = get_browser($userAgent, true);
    

    The User Agent is easily spoofed too, so you can't trust it's the correct one.

    3) Referer:

    $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
    

    The referer header is optional and no many browsers send to the XHR Requests.

    If you are building an API, depending the use case may you can ask for a mandatory header or parameter in order to tell you more information of who is doing the request (Android App, iOS App, Website, etc.) Obviously, that can be easily spoofed.

    So i don't recommend that using for security validations, but if you only want to know in order to log the calls for debug, may be useful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了