简体   繁体   English

如何使用 WP Nonce URL 和 WP Redirect 或 PHP 标头去除&符号

[英]How to get rid of ampersand using WP Nonce URL and WP Redirect or PHP header

My code was working fine:我的代码工作正常:

$registrado = "no";

$redirect_url = site_url( "/pedido-nao-recebido/?mpms2pagarme=retorno&codigo=nao200&mensagem=oui&registrado=$registrado");      

wp_redirect($redirect_url);

exit;

With this, I was being redirected to有了这个,我被重定向到

http://s16138.p360.sites.pressdns.com/pedido-nao-recebido/?mpms2pagarme=retorno&codigo=nao200&mensagem=oui&registrado=no.

Exactly what I need.正是我需要的。

Then I decided to take a security measure, with wp_nonce_url .然后我决定采取安全措施,使用wp_nonce_url

$registrado = "no";

$redirect_url = site_url( "/pedido-nao-recebido/?mpms2pagarme=retorno&codigo=nao200&mensagem=oui&registrado=$registrado");      

//WP Nonce (security measure)
$nonce_redirect_url = wp_nonce_url( $redirect_url, 'pedido-nao-recebido', 'mpms2nonce' );

wp_redirect($nonce_redirect_url);

exit;

Now I get this URL:现在我得到这个网址:

http://s16138.p360.sites.pressdns.com/pedido-nao-recebido/?mpms2pagarme=retorno&codigo=nao200&mensagem=oui&registrado=no&mpms2nonce=aeb5ba40d2.

Because of these amp;因为这些amp; , my code is broke and browser gives me a The s16138.p360.sites.pressdns.com page isn't working . ,我的代码The s16138.p360.sites.pressdns.com page isn't working了,浏览器给了我一个The s16138.p360.sites.pressdns.com page isn't working There is a script on the redirected page that is not running.重定向页面上有一个未运行的脚本。 It goes like this:它是这样的:

//If it is not a subscription request, abort...  
if ( !isset( $_GET['mpms2pagarme'] ) || 'retorno' != $_GET['mpms2pagarme'] || !isset( $_GET['codigo'] ) || !isset( $_GET['mensagem'] )  ) {  
    return;  
}

//Checking WP Nonce
check_admin_referer( 'pedido-nao-recebido', 'mpms2nonce' );

(...)

I tried using php header function instead of wp_redirect , but the same happened (ampersand).我尝试使用 php header函数而不是wp_redirect ,但发生了同样的事情(&符号)。 I tried also esc_url , esc_url_raw , urlencode ...with no success.我也试过esc_urlesc_url_rawurlencode ...但没有成功。

Strange thing... wp_redirect (or header ) only works for me without wp_nonce_url .奇怪的事情...... wp_redirect (或header )只适用于没有wp_nonce_url我。 Should I get rid of the latter?我应该摆脱后者吗? Any other solution?还有其他解决办法吗?

Thanks in advance.提前致谢。

You can use html_entity_decode() to convert &您可以使用html_entity_decode()来转换& back to &回到&

The string is being url encoded somewhere along the way该字符串正在沿途的某个地方进行 url 编码

you can decode it with urldecode你可以用urldecode解码

wp_redirect(urldecode($nonce_redirect_url));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM