문제

abspath()

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

directory()

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

Code Line:-

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

Gives me the following as output:

C:/xampp/htdocs/folder/

When I use

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

It sends me to my index.php in C:/xampp/htdocs/folder/index.php Why its not working with functions?

I want to go to C:/xampp/htdocs/folder/index.php using this

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

- Is there any problem?

도움이 되었습니까?

해결책

The problem is that your functions are echoing your output and not returning it. You'll want to change your functions to:

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

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

So you can use the returned value (namely $_SERVER['DOCUMENT_ROOT'] or '/folder/', in this case) in your string concatentiation.

다른 팁

Your path should URI when using with header .

Soething like that

header('Location:http://yourpath.com/folder');

In the answer you are using a physical location where file residing

try $_SERVER["REQUEST_URI"]

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top