Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass complex URL as parameter in PHP

Tags:

url

php

I'm trying to pass a complex URL as a url parameter but the problem occurs if the url contains & 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'm trying to get a URL as a parameter from a user and redirect user to this URL.

How could I handle this in PHP?


The whole Story:

I'm trying to make some ads analytics on flash files so user submit flash ads to a website which contains a link to the required webpage.

Now,my client needs to know how many times this flash file was clicked.To solve this I 'll till every one who submits flash to write a link to my client webpage and pass the required URL as a parameter as follows

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

by this way I can update my database and get a count for how many times this link was clicked

like image 317
Feras Odeh Avatar asked May 05 '11 12:05

Feras Odeh


1 Answers

Use urlencode() or rawurlencode().


You wrote:

I'm trying to get a URL as a parameter from a user and redirect user to this URL.

But you didn't answer the question - how do you get that URL? How does user provide you with it? Is it written in <input type='text'/>? Or does user click some link that contains URL as one of parameters? Or is passed as ID of some URL that is stored in DB?

One case that comes into my mind - replacing URLs in plain text and sending user to some "redirecting page" before opening real page, so final page does not see HTTP referrer which might contain some secure data (e.g., session ID). In this case, you would write

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

instead of

<a href='redirect.php?link=<?php echo $url; ?>'>
    <?php echo htmlspecialchars($url); ?>
</a>
like image 122
binaryLV Avatar answered Oct 26 '22 12:10

binaryLV