什么是$ _ SERVER的区别['PHP_SELF']和$ _ SERVER ['SCRIPT_NAME']? [英] What's the difference between $_SERVER['PHP_SELF'] and $_SERVER['SCRIPT_NAME']?

查看:123
本文介绍了什么是$ _ SERVER的区别['PHP_SELF']和$ _ SERVER ['SCRIPT_NAME']?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP框架,我用 $ _ SERVER ['SCRIPT_NAME'] 优化的便携性。这样,我也不需要手动配置的路径了。

  $这个 - > BASE_URL = str_replace函数('的index.php','','HTTP://'.$_SERVER ['SERVER_NAME'] $ _ SERVER ['SCRIPT_NAME ']);

但是我注意到 $ _ SERVER ['SCRIPT_NAME'] $ _ SERVER ['PHP_SELF'] 返回完全相同的字符串。那么,有什么区别?我应该如何在它们之间选择?


解决方案

区别

  HTTP://sandbox.php$c$c.eu/g/3e38d.php/test

脚本名称是文件的绝对路径。

PHP_SELF 是(后的.php 与路径一起)

这就像 $ _ SERVER ['SERVER_NAME'] $ _ SERVER ['HTTP_HOST']

  HTTP://sandbox.php$c$c.eu./g/f5093.phpHTTP://sandbox.php$c$c.eu/g/f5093.php

现场一个区别

I have a php framework and I used $_SERVER['SCRIPT_NAME'] to optimize portability. That way I don't need to manually configure the path anymore.

$this->base_url = str_replace('index.php', '', 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']);

But I noticed that $_SERVER['SCRIPT_NAME'] and $_SERVER['PHP_SELF'] returns the exact same string. So, what's the difference? How should I choose between them?

解决方案

Difference

http://sandbox.phpcode.eu/g/3e38d.php/test

Script name is absolute path to file.

PHP_SELF is script you're currently in (along with "path" after .php)

It's like $_SERVER['SERVER_NAME'] and $_SERVER['HTTP_HOST']

http://sandbox.phpcode.eu./g/f5093.php

http://sandbox.phpcode.eu/g/f5093.php

spot one difference

这篇关于什么是$ _ SERVER的区别['PHP_SELF']和$ _ SERVER ['SCRIPT_NAME']?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆