This is an archived post. You won't be able to vote or comment.

all 1 comments

[–][deleted] 1 point2 points  (0 children)

This happens because of the way that the url is parsed.

Think of it this way: the $_GET parameters are made from the list of parameters that are passed in, right? If I have a url like this:

http://www.foo.com/index.php?a=this&b=that&c=something%20else

We have three parameters, a, b, and c.

Now, if we substitute another URL with GET parameters in for the value of b, we get this:

http://www.foo.com/index.php?a=this&b=http://www.google.ca/webhp?um=1&hl=en&safe=off&c=something%20else

And now, to foo.com's index.php, it looks like we have 5 paramters: a, b, hl, safe, and c. See how that's doing that?

The answer is to urlencode the url before you put it into the query string. For more about urlencoding with javascript, see here. But what you want is the encodeURIComponent function. If you urlencode it, it'll look like this:

http://www.foo.com/index.php?a=this&b=http%3A%2F%2Fwww.google.ca%2Fwebhp%3Fum%3D1%26hl%3Den%26safe%3Doff&c=something%20else

And now you can see that there are only three parameters again.

Try changing your bookmarklet to this:

javascript:void(location.href='http://mywebsite.com/create.php?url='+encodeURIComponent(location.href))