officialmorse
officialmorse

Reputation: 24

php get multiple parameters as one

Im slightly stuck with the get variables for a php script. I want to be able to accept a single url via

$_GET["url"]

however i have found that if users pass a url like this in

https://www.google.co.uk/search?q=PHP&oq=PHP&aqs=chrome..69i57j69i60j69i61j69i60l2j69i59.3094j0j4&sourceid=chrome&es_sm=0&ie=UTF-8

the script will only read this

https://www.google.co.uk/search?q=PHP

My question is whether there is a way to read the whole url including the other get keys?

Upvotes: 0

Views: 54

Answers (1)

Brad
Brad

Reputation: 163240

The problem is that you're not encoding things correctly for use in the URL. Reserved characters like & and ? must be encoded, or they become ambiguous.

Use urlencode(). That URL becomes:

https%3A%2F%2Fwww.google.co.uk%2Fsearch%3Fq%3DPHP%26oq%3DPHP%26aqs%3Dchrome..69i57j69i60j69i61j69i60l2j69i59.3094j0j4%26sourceid%3Dchrome%26es_sm%3D0%26ie%3DUTF-8

... which is then safe to use as a value in your query string.

Upvotes: 1

Related Questions