22
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

phpで参照元によって振り分ける処理

Last updated at Posted at 2015-05-25

PHPで参照元によって振り分け処理を行うときのめも

sansyo.php
/* 参照元によって振り分け処理 */
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
if (preg_match("|^https?://[a-zA-Z0-9-]+\.hoge\.jp|", $referer)) {
   // "xxx.hoge.jp" サイト内からのアクセス時の処理。
  
}
else {
 /* 直接アクセス時の処理 */
}

$_SERVER['HTTP_REFERER'] は取得できるとは限らないとのご指摘を受け、
isset($_SERVER['HTTP_REFERER'])の箇所を入れました。

22
29
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?