1

I am working on existing project. At some points it has some poor implementation.

For example I found following code in an action:

<?php
    echo "<script>window.location='/".$this->getRequestParameter("culture")."/profile/".$this->username';</script>"; 
?>

In normal condition above code works fine and redirect user successfully. But problems occurs when username is something like this:

Uneståhl

It converts it into

Unestål

And a server error is returned.

Any idea how to fix this ?

Thanks

5
  • When it is redirected,I saw converted code in browser address bar.. Commented Feb 14, 2012 at 11:17
  • I just tried such thing (with window.location='Uneståhl) and the browser didn't change the value. Tried with IE9 and Chrome. What browser you tried? Commented Feb 14, 2012 at 11:32
  • Independently from your problem: this looks like an attempt to simulate a redirect with JavaScript. You should be using a proper redirect - especially since you are using PHP anyway. Commented Feb 14, 2012 at 11:35
  • So it's likely PHP issue, converting it somewhere. Commented Feb 14, 2012 at 11:38
  • This looks like a character set mismatch problem. The "converted" version looks like UTF-8 expressed in ISO-8859-1. Commented Feb 14, 2012 at 11:40

1 Answer 1

2

You could try using PHP urlencode function:

<?php
    echo "<script>window.location='/".$this->getRequestParameter("culture")."/profile/".urlencode($this->username). "';</script>"; 
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Fixed but It is working with urlencode(). url_encode() is giving me function not found error.
You're right. Sorry for the mistake. I will update the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.