Pass complex URL as parameter in PHP

I am trying to pass a complex URL as a url parameter, but the problem occurs if the URL contains and for example I want to pass the following link as a parameter

http://www.google.ps/search?hl=en&client=firefox-a&hs=42F&rls=org.mozilla%3Aen-US%3Aofficial&q=The+type+%27Microsoft.Practices.ObjectBuilder.Locator%27+is+defined+ in + an + assembly + that + is + not + referenced. + You + must + add + a + reference + to + assembly + & aq = f & aqi = & aql = & oq =

I am trying to get the url as a parameter from the user and redirect the user to that url.

How can I handle this in PHP?


The whole story:

I'm trying to do some analytics of ads on flash files so that users send flash movies to a site that contains a link to the desired web page.

Now my client needs to know how many times this flash file has been clicked. To solve this problem, I want everyone who sent flash to write a link to my client web page and pass the required URL as a parameter as follows

http://myclientwebpage.com/disp.php?link=www.google.com&id=16

This way I can update my database and get a count of the number of times this link was clicked

+8
url php
source share
2 answers

Use urlencode() or rawurlencode() .


You wrote:

I am trying to get the URL as a parameter from a user and redirect the user to that URL.

But you did not answer the question - how to get this URL? How does the user provide this to you? Is this written in <input type='text'/> ? Or does the user click on the link containing the URL as one of the parameters? Or is it passed as the identifier of some URL that is stored in the database?

One case that comes to my mind is replacing the URLs in text form and sending the user to some โ€œredirect pageโ€ before opening the real page, so the last page does not display the HTTP referrer, which may contain some protected data (for example, the identifier session), in which case you should write

 <a href='redirect.php?link=<?php echo rawurlencode($url); ?>'> <?php echo htmlspecialchars($url); ?> </a> 

instead

 <a href='redirect.php?link=<?php echo $url; ?>'> <?php echo htmlspecialchars($url); ?> </a> 
+14
source share

From what I understand, you need to replace & with &amp; .

 $url = str_replace('&', '&amp;', $url); 

& reserved, used to separate GET, &amp; Designed to write an ampersand literal in a URL.

0
source share

All Articles