문제

I am creating a url which has username at the end of it and the username can have dots in it. It can also include dots at the very end.

When i create the url and mail it's link to the user, the dot does appear at the end of the link but not as a part of the link, because of which when the user clicks on the link that dot gets ignored and the wrong url is passed.

The username that i added at the end is a variable name from the database, so am not sure how to get this solved.

도움이 되었습니까?

해결책

Your best bet is to send the email in HTML format. That way you can directly decide what the link is and prevent the users email client from doing its own magic.

Another possibility would be to URL encode the dot as well. See this question/answer: Encode the url including hyphen(-) and dot(.) in php

다른 팁

In other words, you are sending links in plain text and you want to change the algorithms to extract URLs from text used by all the different hundred e-mail clients your recipients read messages with. You obviously cannot.

You can fool most parsing tools if you URL-encode the dot:

http://example.com/foo%2E

... or you can simply generate HTML e-mail messages with proper <a href=""></a> tags.

Your problem will go away if instead of sending the username you send the user id (that probably is a number).

That should be easily handled by email clients.

Another thing that I do, although it requires a bit of more programing is to send short simple URLs that do not have the risk of being mangled with.

For example I will send something like

http://example.com/profile_123711611121

Then on the server side, using URL rewriting I intercept that and pass it to a PHP code that knows what the URL means and does the proper redirect to a more complicated URL like:

http://example.com/users/profile/update_profile.php?id=123711611121

The first URL will be nicely parsed and it can also be easily copy pasted by non tech people.

The second URL may be broken in two lines, not parsed correctly and so on.

In conclusion you are in control of what URLs you email. Make it simple for you and your users! :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top