标头位置无法正常工作 [英] Header location not working properly
问题描述
我的网址为 http://www.website.ro/index .php?subiect = 10046& pag = 1 #1006 ,我在这里没有任何操作(< form action =method =提交后我检查一些输入字段,如果有任何错误,我想重定向。我使用以下代码:
header('Location:/index.php?subiect='.$_GET['subiect'] '&安培; PAG =' $ _ GET [ 'PAG']);出口();
但重定向包括#1006 ,所以我的页面变成 http://www.website.ro/index.php?subiect=10046&pag=1 #1006
我试着在标题中更改位置:
header('Location:http://www.google.com');出口();
需要我的页面是: http://www.google.com #1006
为什么要这样做?
我在第一行有 ob_start()
,我试图删除它。没有效果。重定向stil后的网址#1006 。
如果我的网址是 http://www.website.ro/index.php?subiect=10046&pag=1 ,我使用标题位置我没有问题,但如果url包含#1006重定向后的url 片段标识符,并标识页面的一部分,即使该页面是从另一个URL检索的。
默认情况下,大多数浏览器在无论使用什么状态代码,都会发生3xx重定向。请参阅 URL片段和302重定向了解有关此问题的若干资源。
您可以返回一个包含片段标识符的URI(即使是空的):
header('Location:http://www.google.com/#');
然后用本草稿:
< blockquote>
例外情况是,返回的URI已经有一个片段
标识符。在这种情况下,原始片段标识符MUST NOT不会被
添加到它。
您也可以更改片段标识符 onclick
使用Javascript。
My URL is http://www.website.ro/index.php?subiect=10046&pag=1#1006, and i have a form here with no action (<form action="" method="post">
).
After submit I'm checking some input fields and if there is any error, I want to redirect. I use this code:
header('Location: /index.php?subiect='.$_GET['subiect'].'&pag='.$_GET['pag']); exit();
But the redirect includes #1006 so my page becomes http://www.website.ro/index.php?subiect=10046&pag=1#1006
I tried to change location in the header with:
header('Location: http://www.google.com'); exit();
The page where takes me is : http://www.google.com#1006
Why does it do this?
I have ob_start()
at first line and i tried to deleted it. No effect. The url after redirect stil has #1006.
If my url is http://www.website.ro/index.php?subiect=10046&pag=1 and i use header location i don't have problems, but if the url contains #1006 the url after redirect contains to.
The part after the #
is called the fragment identifier and identifies a part of the page, even if the page is retrieved from another URL.
By default most browsers keep the fragment identifier when a 3xx redirect occurs, regardless of what status code is used. See URL Fragment and 302 redirects for several resources about the matter.
You can return an URI that contains a fragment identifier itself (even an empty one):
header('Location: http://www.google.com/#');
Then that one will be used instead, as specified in this draft:
The exception is when a returned URI already has a fragment identifier. In that case the original fragment identifier MUST NOT be not added to it.
You could also change the fragment identifier onclick
using Javascript.
这篇关于标头位置无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!