18
17

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.

filter_input( INPUT_SERVER, $key ) で取得できない変数

Posted at

REQUEST_TIME_FLOAT, REQUEST_TIME は $_SERVER を直接参照しないと取得できない。

<?php

var_dump(
  $_SERVER["REQUEST_TIME_FLOAT"],
  $_SERVER["REQUEST_TIME"],
  filter_input( INPUT_SERVER, "REQUEST_TIME_FLOAT" ),
  filter_input( INPUT_SERVER, "REQUEST_TIME" )
);
// float(1396327090.6449)
// int(1396327090)
// NULL
// NULL

あと、PHPでHTTP認証している場合に定義される PHP_AUTH_USER, PHP_AUTH_PW なども $_SERVER を直接参照しないと取得できない。

<?php

$user = filter_input( INPUT_SERVER, 'PHP_AUTH_USER');
$pw = filter_input( INPUT_SERVER, 'PHP_AUTH_PW');
if ( ! isset( $user, $pw ) ) {
  header( "WWW-Authenticate: Basic realm=\"?\"" );
  header( "HTTP/1.0 401 Unauthorized" );
  echo "401 Unauthorized";
  exit;
} else {
  echo "ok"; // 一生こっちのブロックにはこない
}
18
17
2

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
18
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?