Php URL在WordPress中被双重编码
我有一个自定义用户密码重置页面,它工作正常,发送一封带有唯一URL的电子邮件来重置密码,例如:Php URL在WordPress中被双重编码,php,wordpress,encoding,character-encoding,urlencode,Php,Wordpress,Encoding,Character Encoding,Urlencode,我有一个自定义用户密码重置页面,它工作正常,发送一封带有唯一URL的电子邮件来重置密码,例如: https://website.org/reset-password?action=rp&key=chMOWDgCb8h7eFZZby1w&login=Test%20User 当我将URL放入浏览器时,我会被定向到: https://website.org/reset-password?action=rp&key=chMOWDgCb8h7eFZZby1w&login=
https://website.org/reset-password?action=rp&key=chMOWDgCb8h7eFZZby1w&login=Test%20User
当我将URL放入浏览器时,我会被定向到:
https://website.org/reset-password?action=rp&key=chMOWDgCb8h7eFZZby1w&login=Test%2520User
如果我手动从
%2520
中删除25
,URL会工作,但我不知道如何防止它对这些字符进行双重编码。这是因为%20被编码为文本而不是空格
因此,当您生成链接时,它应该是:
your_function_to_generate_password_link('https://website.org/reset-your-password?action=rp&key=chMOWDgCb8h7eFZZby1w&login=Test User');
而不是:
your_function_to_generate_password_link('https://website.org/reset-your-password?action=rp&key=chMOWDgCb8h7eFZZby1w&login=Test%20User');
我怀疑您目前正在做类似的事情(或者wordpress正在对其进行编码):
链接本身包含%20
而不是一个文本空间:
如果要运行两次htmlentities,会发生以下情况:
$test = " ";
$first_try = htmlentities($test); // outputs %20
echo $first_try; // outputs %20
echo htmlentities($first_try); // outputs %2520
%25
是%
的实体代码,由于2
和0
不需要编码,它导致:%2520
这是因为%20被编码为文本而不是空格
因此,当您生成链接时,它应该是:
your_function_to_generate_password_link('https://website.org/reset-your-password?action=rp&key=chMOWDgCb8h7eFZZby1w&login=Test User');
而不是:
your_function_to_generate_password_link('https://website.org/reset-your-password?action=rp&key=chMOWDgCb8h7eFZZby1w&login=Test%20User');
我怀疑您目前正在做类似的事情(或者wordpress正在对其进行编码):
链接本身包含%20
而不是一个文本空间:
如果要运行两次htmlentities,会发生以下情况:
$test = " ";
$first_try = htmlentities($test); // outputs %20
echo $first_try; // outputs %20
echo htmlentities($first_try); // outputs %2520
%25
是%
的实体代码,由于2
和0
不需要编码,它的结果是:%2520