0

I have a small problem with my PHP script. I want to be able to have a URL within a query string so it would look like this:

http://example.com/?url=http://google.com/

This works absolutely fine and $_GET['url'] will return http://google.com.

The problem is when the URL in my query string already has query string, for example:

http://example.com/?url=http://www.amazon.com/MP3-Music-Download/b/ref=sa_menu_mp3_str?ie=UTF8&node=163856011

will return:

http://www.amazon.com/MP3-Music-Download/b/ref=sa_menu_mp3_str?ie=UTF8

and I want it to return:

http://www.amazon.com/MP3-Music-Download/b/ref=sa_menu_mp3_str?ie=UTF8&node=163856011

I am using PHP for server side.

Could anybody please help?

Update

I am using Codeigniter, so if this is the reason why it isn't working as it should then please let me know.

2 Answers 2

3

You need to encode the url passed as query argument:

  • If you send it from PHP, use urlencode or rawurlencode.
  • If you send it from JS, use encodeURIComponent.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I will use that! I might also just switch to the POST method as well!
1

Use urldecode() to pass query string

2 Comments

urlencode() ... I got the question wrong first also ... or perhaps the OP is not clear enough? I now don't know ;)
Thanks! I am using jQuery, but the urlencode() function will come in useful as my app progresses! ;)

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.