php https server_PHP: $_SERVER - Manual

Guide to URL paths...

Data: $_SERVER['PHP_SELF']

Data type: String

Purpose: The URL path name of the current PHP file, including path-info (see $_SERVER['PATH_INFO']) and excluding URL query string. Includes leading slash.

Caveat: This is after URL rewrites (i.e. it's as seen by PHP, not necessarily the original call URL).

Works on web mode: Yes

Works on CLI mode: Tenuous (emulated to contain just the exact call path of the CLI script, with whatever exotic relative pathname you may call with, not made absolute and not normalised or pre-resolved)

Data: $_SERVER['SCRIPT_NAME']

Data type: String

Purpose: The URL path name of the current PHP file, excluding path-info and excluding URL query string. Includes leading slash.

Caveat: This is after URL rewrites (i.e. it's as seen by PHP, not necessarily the original call URL).

Caveat: Not set on all PHP environments, may need setting via preg_replace('#\.php/.*#', '.php', $_SERVER['PHP_SELF']).

Works on web mode: Yes

Works on CLI mode: Tenuous (emulated to contain just the exact call path of the CLI script, with whatever exotic relative pathname you may call with, not made absolute and not normalised or pre-resolved)

Data: $_SERVER['REDIRECT_URL']

Data type: String

Purpose: The URL path name of the current PHP file, path-info is N/A and excluding URL query string. Includes leading slash.

Caveat: This is before URL rewrites (i.e. it's as per the original call URL).

Caveat: Not set on all PHP environments, and definitely only ones with URL rewrites.

Works on web mode: Yes

Works on CLI mode: No

Data: $_SERVER['REQUEST_URI']

Data type: String

Purpose: The URL path name of the current PHP file, including path-info and including URL query string. Includes leading slash.

Caveat: This is before URL rewrites (i.e. it's as per the original call URL). *

*: I've seen at least one situation where this is not true (there was another $_SERVER variable to use instead supplied by the URL rewriter), but the author of the URL rewriter later fixed it so probably fair to dismiss this particular note.

Caveat: Not set on all PHP environments, may need setting via $_SERVER['REDIRECT_URL'] . '?' . http_build_query($_GET) [if $_SERVER['REDIRECT_URL'] is set, and imperfect as we don't know what GET parameters were originally passed vs which were injected in the URL rewrite] --otherwise-- $_SERVER['PHP_SELF'] . '?' . http_build_query($_GET).

Works on web mode: Yes

Works on CLI mode: No

Data: $_SERVER['PATH_INFO']

Data type: String

Purpose: Find the path-info, which is data after the .php filename in the URL call. It's a strange concept.

Caveat: Some environments may not support it, it is best avoided unless you have complete server control

Works on web mode: Yes

Works on CLI mode: No

Note that if something is not set it may be missing from $_SERVER, or it may be blank, so use PHP's 'empty' function for your test.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值