• <tfoot id='ALsr3'></tfoot>

        <legend id='ALsr3'><style id='ALsr3'><dir id='ALsr3'><q id='ALsr3'></q></dir></style></legend>

        <small id='ALsr3'></small><noframes id='ALsr3'>

          <bdo id='ALsr3'></bdo><ul id='ALsr3'></ul>
        <i id='ALsr3'><tr id='ALsr3'><dt id='ALsr3'><q id='ALsr3'><span id='ALsr3'><b id='ALsr3'><form id='ALsr3'><ins id='ALsr3'></ins><ul id='ALsr3'></ul><sub id='ALsr3'></sub></form><legend id='ALsr3'></legend><bdo id='ALsr3'><pre id='ALsr3'><center id='ALsr3'></center></pre></bdo></b><th id='ALsr3'></th></span></q></dt></tr></i><div id='ALsr3'><tfoot id='ALsr3'></tfoot><dl id='ALsr3'><fieldset id='ALsr3'></fieldset></dl></div>
      1. PHP 中的基本 URL

        Base URL in PHP(PHP 中的基本 URL)

          1. <legend id='LiCNI'><style id='LiCNI'><dir id='LiCNI'><q id='LiCNI'></q></dir></style></legend>

            <i id='LiCNI'><tr id='LiCNI'><dt id='LiCNI'><q id='LiCNI'><span id='LiCNI'><b id='LiCNI'><form id='LiCNI'><ins id='LiCNI'></ins><ul id='LiCNI'></ul><sub id='LiCNI'></sub></form><legend id='LiCNI'></legend><bdo id='LiCNI'><pre id='LiCNI'><center id='LiCNI'></center></pre></bdo></b><th id='LiCNI'></th></span></q></dt></tr></i><div id='LiCNI'><tfoot id='LiCNI'></tfoot><dl id='LiCNI'><fieldset id='LiCNI'></fieldset></dl></div>
          2. <small id='LiCNI'></small><noframes id='LiCNI'>

              <tbody id='LiCNI'></tbody>
              <bdo id='LiCNI'></bdo><ul id='LiCNI'></ul>
              <tfoot id='LiCNI'></tfoot>

                • 本文介绍了PHP 中的基本 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有点进退两难,这困扰了我很长一段时间.我有一个本地测试服务器,设置如下:127.0.0.1/

                  I've got a bit of a dilemma, and it's been bothering me for quite some time. I have a local testing server that's set up like so: 127.0.0.1/

                  我的网站在离线模式下如下所示:

                  My website in offline mode looks like this:

                  127.0.0.1/websitename/index.php
                  

                  我的网站实时版本如下所示:

                  My live version of the website looks like this:

                  websitename.com/index.php
                  

                  我有几乎所有链接的基本脚本,除了包括页眉和页脚文件.

                  I've got the base script for almost all of the links, except for the including header and footer files.

                  页脚和页眉文件中的链接除了主页(在网站的根目录)之外都可以使用.

                  The links in the footer and header files work except for the home page (on the root of the website).

                  谁能将我重定向到为离线和在线进行多子目录基础 URL 链接的正确方法?

                  Could anyone redirect me to a proper method of doing multi sub directory base URL linking for both offline and online?

                  我已经修改了大部分 $_SERVER[] 标记和属性,以及 parse_url().

                  I’ve tinkered around with most of the $_SERVER[] tags and attributes, as well as parse_url().

                  推荐答案

                  我已经修改了大部分 $_SERVER[] 标签和属性,以及 parse_url().

                  I’ve tinkered around with most of the $_SERVER[] tags and attributes, as well as parse_url().

                  不要修补它们.没有干净/自动化的方式来做你正在做的事情.只需在配置文件中手动设置基本路径 &再也不用担心它——相对路径.而如果需要设置base URL,过程类似.

                  Don’t tinker with them. There’s no clean/automated way to do what you are doing. Just set a base path manually in a config file & don’t worry about it—relative paths—ever again. And if you need to set a base URL, the process is similar.

                  就文件基本路径而言,您应该像这样显式设置 $BASE_PATH:

                  So as far as a file base path goes, you should explicitly set a $BASE_PATH like this:

                  $BASE_PATH = '/full/path/to/your/codebase/here/';
                  

                  如果您不知道您的文件系统基本路径是什么,只需将这行代码放在您的 PHP 代码中即可;比如 index.php:

                  If you don’t know what your file system base path is, just place this line of code in your PHP code; like index.php:

                  echo "Your path is: " . realpath(dirname(__FILE__)) . "<br />";
                  

                  然后加载该页面.靠近顶部的某处将是这样的文字:

                  Then load that page. Somewhere near the top will be this text:

                  你的路径是:/full/path/to/your/codebase/here/

                  Your path is: /full/path/to/your/codebase/here/

                  然后使用该设置,您可以将代码更改为如下所示:

                  Then with that set you can change your code to be something like this:

                  然后像这样设置你的 include_once:

                  And then set your include_once like this:

                  include_once $BASE_PATH  . 'includes/myfile.php';
                  

                  有些人可能会说您应该直接使用 $_SERVER['DOCUMENT_ROOT'] 甚至 dirname(__FILE__) ,这意味着您可以通过这种方式简化代码可移植性.但是为安装设置文件路径的方式可能会有所不同,因此它永远无法正常工作&你被奇怪的服务器怪癖缠住的机会很高.

                  Some might say you should use $_SERVER['DOCUMENT_ROOT'] or even dirname(__FILE__) directly with the implication being that you can simplify code portability that way. But the way file paths are set for installs can vary so it just never works well & the chances of you getting snagged on an odd server quirk is high.

                  当您移动代码时,最好只在配置文件中手动设置 $BASE_PATH,而不是处理像 $_SERVER 这样的 PHP 常量不存在而引起的头痛问题安装、设置和配置.

                  It’s always best to just to manually set a $BASE_PATH in a config file when you move code than deal with the headaches caused by PHP constants like $_SERVER not being consistent between installs, setups & configurations.

                  就基本 URL 而言,只要在本地开发设置中遵循相同的想法即可:

                  And as far as a base URL goes, just follow the same thinking with this being on your local development setup:

                  $BASE_URL = '/websitename/';
                  

                  这是在您的生产服务器上:

                  And this being on your production server:

                  $BASE_URL = '/';
                  

                  所以设置了 $BASE_URL 然后你可以这样做:

                  So with that $BASE_URL set then you can just do this:

                  我有几乎所有链接的基本脚本,除了包括页眉和页脚文件.

                  I’ve got the base script for almost all of the links, except for the including header and footer files.

                  现在只需在您可能需要通过带有 $BASE_URL 的 URL 请求的任何路径之前添加 &你应该很高兴.

                  Now just prepend any path you might need requested via a URL with $BASE_URL & you should be good to go.

                  这篇关于PHP 中的基本 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <tbody id='SaGLg'></tbody>
                  <legend id='SaGLg'><style id='SaGLg'><dir id='SaGLg'><q id='SaGLg'></q></dir></style></legend>

                      <small id='SaGLg'></small><noframes id='SaGLg'>

                          • <bdo id='SaGLg'></bdo><ul id='SaGLg'></ul>
                            <tfoot id='SaGLg'></tfoot>
                          • <i id='SaGLg'><tr id='SaGLg'><dt id='SaGLg'><q id='SaGLg'><span id='SaGLg'><b id='SaGLg'><form id='SaGLg'><ins id='SaGLg'></ins><ul id='SaGLg'></ul><sub id='SaGLg'></sub></form><legend id='SaGLg'></legend><bdo id='SaGLg'><pre id='SaGLg'><center id='SaGLg'></center></pre></bdo></b><th id='SaGLg'></th></span></q></dt></tr></i><div id='SaGLg'><tfoot id='SaGLg'></tfoot><dl id='SaGLg'><fieldset id='SaGLg'></fieldset></dl></div>