I want to have a 404 page that can detect if a user has come to that page either via my site, via my shortened URL or via another site, and I am making it using PHP. I am slowly getting to grips with PHP and this may well be a simple question, but I am quite tired to be honest and have no caffeine in my system, and I am wanting to tie up any loose ends in my portfolio as soon as possible.

我想要一个404页面,它可以检测用户是否通过我的站点,通过我的缩短的URL或者通过其他站点访问该页面,我使用的是PHP。我正在慢慢地掌握PHP,这可能是一个简单的问题,但说实话我很累,我的系统中没有咖啡因,我想尽快解决我的投资组合中的任何问题。

I have found the $_SERVER['HTTP_REFERER']; PHP variable gives me the entire URL, which is a start. Is there a way that this can give me only the root domain, either via another variable or a function, bearing in mind that some referrers may be using http:// and some https:// (so simply starting from the seventh character would not always work)? That way, I can match the URL based on two (or more) predefined addresses and produce the content that relates to that domain.

我找到了$_SERVER['HTTP_REFERER'];PHP变量为我提供了整个URL,这是一个开始。是否有一种方法可以只给我根域,通过另一个变量或一个函数,记住一些引用者可能使用http://和https://(所以仅仅从第7个字符开始并不总是有效)?这样,我就可以根据两个(或多个)预定义地址匹配URL,并生成与该域相关的内容。

3 个解决方案

#1


40

parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST)

See http://php.net/manual/en/function.parse-url.php.

见http://php.net/manual/en/function.parse-url.php。

Note though that the referer is terrifically easy to spoof, so it's hardly reliable.

请注意,尽管引用者非常容易被欺骗,所以它几乎不可靠。

更多相关文章

  1. php如何跨站抓取别的站点的页面的补充
  2. (T_ENCAPSED_AND_WHITESPACE),期望标识符(T_STRING)或变量(T_VARI
  3. php static静态变量及方法详解
  4. 如何将结果输入变量MYSQL
  5. thinkphp环境变量.env配置
  6. smarty模板引擎变量的传递方法
  7. PHP会话变量没有转移到我登录的页面,但是会话ID是
  8. php变量函数,回调函数
  9. PHP 站点相对包含,路径的问题解决方法(include,require)

随机推荐

  1. Qt for Android(安卓)拉起微信登录、分享
  2. Android(安卓)API Guides---App Manifest
  3. Android应用优化之内存概念
  4. Android跨进程通信
  5. Delphi XE5 for android 调用Java类库必
  6. Android如何实现ListView的Item松开渐变
  7. android java.lang.SecurityException: P
  8. Android客户端与J2EE服务器的互联
  9. Android关于常用正则号码类Util
  10. 我们把 iOS 的 Cocoa Touch 移植到了 And