Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass a URL with multiple parameters into a URL?

Basically I'm trying to pass a URL like this:

www.foobar.com/?first=1&second=12&third=5 

into a URL like this:

http://www.facebook.com/sharer.php?&t=FOOBAR&u=http://www.foobar.com/first=12&sec=25&position=2 

It only recognizes the first parameter. I'm having the same problem with LinkedIn and Twitter sharing, so it must be something I'm doing wrong.

like image 960
DormoTheNord Avatar asked Feb 23 '11 19:02

DormoTheNord


People also ask

How do you send a URL with two variables?

$vars = array('email' => $email_address, 'event_id' => $event_id); $querystring = http_build_query($vars); $url = "http://localhost/main.php?" . $querystring; Additionally, if $event_id is in your session, you don't actually need to pass it around in order to access it from different pages.

Can there be multiple in a URL?

What triggers this issue? There are internal URLs in the web resource that contain multiple ampersands (“&”) and, consequently, multiple parameters.

How many query string parameters can be added into a URL?

Although officially there is no limit specified by RFC 2616, many security protocols and recommendations state that maxQueryStrings on a server should be set to a maximum character limit of 1024.


1 Answers

Rather than html encoding your URL parameter, you need to URL encode it:

http://www.facebook.com/sharer.php?&t=FOOBAR&u=http%3A%2F%2Fwww.foobar.com%2F%3Ffirst%3D12%26sec%3D25%26position%3D 

You can do this easily in most languages - in javascript:

var encodedParam = encodeURIComponent('www.foobar.com/?first=1&second=12&third=5'); // encodedParam = 'http%3A%2F%2Fwww.foobar.com%2F%3Ffirst%3D12%26sec%3D25%26position%3D' 

(there are equivalent methods in other languages too)

like image 175
Dexter Avatar answered Oct 01 '22 09:10

Dexter