Reputation: 33
Until now I was only reading but now I have my first question and hopefully someone can help me with it.
You perform a search by submit:
input: Lösung? Tösung& -> url: http://127.0.0.1/?search=Lösung%3F+Tösung%26
If you are not logged in, then I redirect (location header) the search with url_encode to login:
...login/return_url=http%3A%2F%2F127.0.0.1%2F%3Fsearch%3DLösung%3F+Tösung%26amp%3B
I get 'wrong' results for $_GET['return_url']:
http://127.0.0.1/?search=Lösung? Tösung&
When logged in and after redirecting (not encoding the url again) I get:
url: http://127.0.0.1/?search=Lösung? Tösung& -> input: Lösung? Tösung
Maybe I should redirect with encoding the url before? But I get an error (url not readable?)
header("Location: ".urlencode(url)."");
How can I achieve that after redirecting I still get the same results like in first url and not losing special characters like in example?
Maybe it is simple but until now I did not get the correct result and hope that you can help.
Upvotes: 3
Views: 4524
Reputation: 56
The first thing i see is the wrong url is given. The format of a $_GET[] in the URL should be
http:// domain.com/index.php?myvar=var&myfoo=foo
For the first var after your page you use a '?' For every var after that you couple them with '&'
urlencode and urldecode fixes your problem with the chars.
$url= "http://www.mysite.com/index.php?search=location&option=europe";
$encoded = urlencode($url);
// result: http%3A%2F%2Fwww.mysite.com%2Findex.php%3Fsearch%3Dlocation%26option%3Deurope
$decoded = urldecode($encoded);
// result: http://www.mysite.com/index.php?search=location&option=europe
With your url:
$url= "http://127.0.0.1/?search=Lösung%3F+Tösung%26";
encoded:
http%3A%2F%2F127.0.0.1%2F%3Fsearch%3DL%C3%B6sung%253F%2BT%C3%B6sung%2526
decoded:
http://127.0.0.1/?search=Lösung%3F+Tösung%26
Upvotes: 1