开发者

How to get special char as a parameter from url

I have a url like http://localhost.com/api/authenticateuser?user=demo&pass=demo#123

But when i use $_GET['pass'] i am only abl开发者_运维百科e to get value of $_GET['pass'] is "demo" not "demo#123"

is there any way to get parameter value as "demo#123"

Thanks


You have to urlencode your url, in order to escape special / forbidden chars.

http://php.net/manual/en/function.urlencode.php


The part after the # is called the fragment identifier, and it is not sent to the server. If you want to send it that way, you need to use encodeURIComponent.


You need to ensure the URL is properly escaped - see URL Escape Codes for a reference. For example, # is supposed to be escaped to %23.

There are many ways to do this, including using JavaScript function encodeURIComponent (for dynamically generated links).


Well, i'm working on an AngularJS application which checks if the user is logged on every request.

At certain point app redirects the user to /login controller passing user's current state using the parameter "next".

So i've gotten this URL "http://test.dev/login/?next=/#/foo/bar" and i wanted to get the value of $_GET['next'] but wait... Why the heck is that returning only '/' ?

Well, turned out that i needed to use JavaScript method encodeURIComponent() to generate the URL.

Then this: http://test.dev/login/?next=/#/foo/bar, became this: http://test.dev%2Flogin%2F%3Fnext%3D%2F%23%2Ffoo%2Fbar and PHP was able to handle this just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜