简体   繁体   English

如何知道用户来自站点A

[英]How to know the user is from site A

I have certain API for site B, but i need to let site B know when is the right time to execute them. 我有用于站点B的某些API,但是我需要让站点B知道何时是执行它们的正确时间。 The right time is when user come from site A. How can i make sure the visitor is from site A? 正确的时间是用户来自站点A的时间。如何确定访问者来自站点A? the programming language of site B maybe C# aspx, or php. 网站B的编程语言可能是C#aspx或php。

update I need to make the entire site B know about user from site A. or else new page or redirection would cause the script not working. 更新我需要使整个站点B都知道站点A的用户。否则,新页面或重定向将导致脚本无法正常工作。

You need to look at the HTTP Referer Header: 您需要查看HTTP Referer标头:

$_SERVER['HTTP_REFERER']

See PHP Documentation for more HTTP Headers 有关更多HTTP标头,请参见PHP文档

As the request contains the header referer. 由于请求包含标头引用。 In java, you can use this. 在Java中,您可以使用它。

String referrer = request.getHeader("referer");

Check the network panel in chrome.Click on the request and See under the headers tab. 检查chrome中的网络面板。点击请求,然后在标题标签下查看。 You will see the referer as google, if you visit a page from google. 如果您访问Google的页面,则将引荐来源网址为Google。

You can use this function in asp.net to get the referral URL 您可以在asp.net中使用此功能获取引荐网址

    public static string GetReferalUrl()
    {
        var lStrRefUrl = "";
        if (HttpContext.Current.Request.UrlReferrer != null)
            lStrRefUrl = HttpContext.Current.Request.UrlReferrer.Host;
        return lStrRefUrl;
    }

You can every information form HttpContext.Current.Request about the request. 您可以从HttpContext.Current.Request每一个信息中获取有关请求的信息。

Note that the user may hide about the server information. 请注意,用户可能会隐藏服务器信息。 It can also hide weather it is IIS or other web server. 它也可以隐藏是IIS或其他Web服务器的天气。 It's just a configuration which you need to remove form the server or from the individual site. 这只是您需要从服务器或从单个站点中删除的配置。

Here is a good link about the request headers. 这是有关请求标头的良好链接。
How to dump ASP.NET Request headers to string 如何将ASP.NET请求标头转储到字符串

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

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