php - 带标题位置的绝对路径

标签 php absolute-path document-root

绝对路径()

function abspath()
{
    echo $_SERVER['DOCUMENT_ROOT'];
}

目录()

function directory()
{
    echo '/folder/';
}

代码行:-

header('Location:'.abspath().directory());

给我以下输出:

C:/xampp/htdocs/folder/

当我使用时

header('Location:'.$_SERVER['DOCUMENT_ROOT'];.directory());

它将我发送到 C:/xampp/htdocs/folder/index.php 中的 index.php 为什么它不能与函数一起使用?

我想使用它转到C:/xampp/htdocs/folder/index.php

header('Location:'.abspath().directory());

- 有什么问题吗?

最佳答案

问题在于您的函数正在回显您的输出而不返回它。您需要将功能更改为:

function abspath()
{
    return $_SERVER['DOCUMENT_ROOT'];
}

function directory()
{
    return '/folder/';
}

因此,您可以在字符串连接中使用返回值(即$_SERVER['DOCUMENT_ROOT'] 或'/folder/',在本例中)。

关于php - 带标题位置的绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9821834/

相关文章:

php - Fontawesome 字体在 Assets :install and assetic:dump 后失败

SVG "Move"命令 : Absolute path to Relative Path

java - 从 java 代码执行 shell 脚本并将终端的输出附加到 .txt 文件

php - 使用 mysql 组合列和样条 Highcharts

php - MySQL 行排序 : How to set up and use a `position` column for row ordering?

php - cakephp 中的模型和行为使用

MSBuild 干净目录字符串

Apache 多个 DocumentRoot

node.js - 是否可以将文件系统根目录和/或文档根目录设置为文件系统的某个子目录?

php - 当前 PHP 脚本相对于文档根目录的路径