zoukankan      html  css  js  c++  java
  • PHP_SELF、 SCRIPT_NAME、 REQUEST_URI差别

    $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在使用方法上是很相似的,他们返回的都是与当前正在使用的页面地址有关的信息。这里列出一些相关的样例,帮助确定哪些是在你的脚本最适合的。

    $_SERVER[’PHP_SELF’]

    • http://www.yoursite.com/example/ — – — /example/index.php
    • http://www.yoursite.com/example/index.php — – — /example/index.php
    • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php
    • http://www.yoursite.com/example/index.php/dir/test — – — /dir/test

    当我们使用$_SERVER['PHP_SELF']的时候,不管訪问的URL地址是否有index.php,它都会自己主动的返回 index.php.可是假设在文件名称后面再加斜线的话,就会把后面全部的内容都返回在$_SERVER['PHP_SELF']。

    $_SERVER['REQUEST_URI']

    • http://www.yoursite.com/example/ — – — /
    • http://www.yoursite.com/example/index.php — – — /example/index.php
    • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php?a=test
    • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php/dir/test

    $_SERVER['REQUEST_URI']返回的是我们在URL里写的精确的地址,假设URL仅仅写到”/”,就返回 “/”

    $_SERVER['SCRIPT_NAME']

    • http://www.yoursite.com/example/ — – — /example/index.php
    • http://www.yoursite.com/example/index.php — – — /example/index.php
    • http://www.yoursite.com/example/index.php — – — /example/index.php
    • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php

    在全部的返回中都是当前的文件名称/example/index.php

    $_SERVER[PHP_SELF], $_SERVER[SCRIPT_NAME], $_SERVER['REQUEST_URI'] 在使用方法上是很相似的。他们返回的都是与当前正在使用的页面地址有关的信息。这里列出一些相关的样例,帮助确定哪些是在你的脚本最适合的。

    $_SERVER[’PHP_SELF’]

    • http://www.yoursite.com/example/ — – — /example/index.php
    • http://www.yoursite.com/example/index.php — – — /example/index.php
    • http://www.yoursite.com/example/index.php?a=test — – — /example/index.php
    • http://www.yoursite.com/example/index.php/dir/test — – — /dir/test

    当我们使用$_SERVER['PHP_SELF']的时候。不管訪问的URL地址是否有index.php,它都会自己主动的返回 index.php.可是假设在文件名称后面再加斜线的话,就会把后面全部的内容都返回在$_SERVER['PHP_SELF']。

    $_SERVER['REQUEST_URI']

    • http://www.yoursite.com/example/ — – — /
    • http://www.yoursite.com/example/index.php — – — /example/index.php
    • http://www.yoursite.com/example/index.php?

      a=test — – — /example/index.php?a=test

    • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php/dir/test

    $_SERVER['REQUEST_URI']返回的是我们在URL里写的精确的地址,假设URL仅仅写到”/”。就返回 “/”

    $_SERVER['SCRIPT_NAME']

    • http://www.yoursite.com/example/ — – — /example/index.php
    • http://www.yoursite.com/example/index.php — – — /example/index.php
    • http://www.yoursite.com/example/index.php — – — /example/index.php
    • http://www.yoursite.com/example/index.php/dir/test — – — /example/index.php

    在全部的返回中都是当前的文件名称/example/index.php

  • 相关阅读:
    通过CMMI5的国内企业有几个?这个认证是不是很牛啊?
    CNUTCon 全球运维技术大会2017
    新浪微博基于Docker的混合云架构与应用实践-DockerInfo
    k8s~为服务添加ingress的实现
    springboot~HttpPut开启application/x-www-form-urlencoded
    K8s~为pod添加sidecar进行日志收集
    k8s~部署EFK框架
    springboot~Transactional注解的注意事项
    CentOS 6.4 快速安装Nginx笔记
    去掉NSString中的HTML标签
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5137114.html
Copyright © 2011-2022 走看看