Home > Backend Development > PHP Tutorial > 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
Release: 2016-08-04 09:19:07
Original
1547 people have browsed it

1. One is

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

The other one is

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

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>
Copy after login
Copy after login

The other one is

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template