简体   繁体   中英

php header location - french characters

When the $urlGoBack variable contains a french accented character like "é" the following doesn't work properly, even tho I previously ensured it's being passed on to header like it should, using the mb_convert_encoding() function.

header("Location: " . $urlGoBack);

The URL I'm being taken to has "é" changed to %E9, which is its URL equivalent I guess.

HTML charset is iso-8859-1, whereas mb_detect_encoding($urlGoBack) returns UTF-8.

On the other hand, if I try converting it with

$urlGoBack = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $urlGoBack);

or

$urlGoBack = mb_convert_encoding($urlGoBack, "ISO-8859-1", "UTF-8"); 

then mb_detect_encoding($urlGoBack) returns ASCII and "é" is gone, and the URL gets wrong. Surprisingly tho, it's exactly the same result when I try the seemingly trivial

$urlGoBack = mb_convert_encoding($urlGoBack , "UTF-8", "UTF-8");

Any suggestions? Thanks.

I think you need to encode url like this

header("Location: " . urldecode($urlGoBack));

Refer php.net

您需要使用urlencode($ urlGoBack),如下所示:

header("Location: " . urlencode($urlGoBack));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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