我有这些棘手的问题。
在我的网站上,我允许使用字符 åäö
进行注册,并且我有链接到他们的个人资料的友好 URL,因此假设 URL 如下所示:
example.com/profile/åäöismyname/
并且 userfriend
变量是$_GET['vanlig']
。
现在,这称为 example.com/profile/åäömyname&favorisera
$_GET['vanlig']
现在被称为 åäömyname&favorisera
而不是åäömyname
和 &favorisera
未被调用。
只要我的 $_GET
变量中没有 åäö
,这个方法就可以正常工作,然后正确调用 &favorisera
。
对此有何建议?更改他们的友好名称不是一个选择。因为这可能会导致数据库中出现重复名称。
我使用 nginx 作为友好 URL 的网络服务器。
编辑:
我尝试了此操作
$userid = urlencode($userid);
<div class="privat" onclick="window.location = '/profil/<?=$userid?>&favorisera'" style="cursor:pointer;" title=""></div>
,但没有成功,链接显示(作为源代码中的实际示例):
<div class="privat" onclick="window.location = '/profil/k%C3%A5taelin&favorisera'" style="cursor:pointer;" title=""></div>
单击时,我返回 $_GET['vanlig'] 的 var 转储,这会导致 string(19) "kåtaelin&无论如何,最喜欢的。
I have these tricky problems.
On my site I allow registrations with the characters åäö
in them, and I have friendly URLs linking to their profile, so lets say an URL looks like this:
example.com/profile/åäöismyname/
and the userfriendly
variable is $_GET['vanlig']
.
Now, this is called example.com/profile/åäömyname&favorisera
$_GET['vanlig']
is now called as åäömyname&favorisera
instead of åäömyname
, and &favorisera
is not called.
This works perfectly fine as long as I don't have åäö
in the $_GET
variable, &favorisera
is then called properly.
Any suggestions to this? Changing their friendly names is not an option. Since this may cause duplicate names in the DB.
I'm using nginx as a webserver for friendly URLs.
EDIT:
i tried this
$userid = urlencode($userid);
<div class="privat" onclick="window.location = '/profil/<?=$userid?>&favorisera'" style="cursor:pointer;" title=""></div>
without any success, the linking shows ( as an actual example from the source code ) :
<div class="privat" onclick="window.location = '/profil/k%C3%A5taelin&favorisera'" style="cursor:pointer;" title=""></div>
When clicked, i return a var dump of $_GET['vanlig'], which results in string(19) "kåtaelin&favorisera" anyway.
发布评论
评论(2)
您需要一个问号来启动查询字符串。
You need a question mark to start the query string.
& 符号是表示新变量的特殊字符,因此请尝试使用 urlencode()在链接字符串上,然后在操作时 urldecode()您的页面或数据库。
The ampersand is a special character signifying a new variable, so try using urlencode() on your strings for the links, and then urldecode() when you manipulate it in your page or database.