Home  >  Article  >  Backend Development  >  Why does the relative path jump succeed but the absolute path jump fails? (see code for details)

Why does the relative path jump succeed but the absolute path jump fails? (see code for details)

WBOY
WBOYOriginal
2016-08-04 09:19:071477browse

1. One is

<code><a href="<php>echo $_SERVER['HTTP_HOST'].'/home/shop/cate/id/'.$goods['id']</php>" target="_blank">{$goods['name']}</a>
</code>

The other one is

<code><a href="<php>echo '/home/shop/cate/id/'.$goods['id']</php>" target="_blank">{$goods['name']}</a>
</code>

2. The first one is an absolute path, but the jump page is empty, but if you refresh the page, it will be displayed.
The second one is a relative path, but the content comes out directly after the jump

Excuse me, why is this?
This code is executed under thinkphp, is the template writing method of thinkphp.
Is the problem I encountered encountered by all PHP, or is it caused by the unique syntax of thinkphp?

Reply content:

1. One is

<code><a href="<php>echo $_SERVER['HTTP_HOST'].'/home/shop/cate/id/'.$goods['id']</php>" target="_blank">{$goods['name']}</a>
</code>

The other one is

<code><a href="<php>echo '/home/shop/cate/id/'.$goods['id']</php>" target="_blank">{$goods['name']}</a>
</code>

2. The first one is an absolute path, but the jump page is empty, but if you refresh the page, it will be displayed.
The second one is a relative path, but the content comes out directly after the jump

Excuse me, why is this?
This code is executed under thinkphp, is the template writing method of thinkphp.
Is the problem I encountered encountered by all PHP, or is it caused by the unique syntax of thinkphp?

You can’t use $_SERVER['HTTP_HOST'] directly because there is no http://. Just add http:// before the absolute path

You can find out by right-clicking and viewing the source code. It should be the reason mentioned above

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn