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 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line