Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass URL in URL (as GET parameter) using PHP?

I'm having some problems passing URL's as GET parameter. When I try to access:

http://www.linkebuy.com.br/linkebuy/parceiro?url=http%3A%2F%2Fwww.google.com

I get the following message:

Unexpected error.

However, if I go for:

http://www.linkebuy.com.br/linkebuy/parceiro?url=123

Everything works just fine (it redirects to an inexistent site - 123 -, of course, but it does the expected). By elimination I can say there's something wrong with the url parameter, but what is it?

OBS: I'm using rawurlencode() to encode the URL.

EDIT: Code you asked...

In the first view, where the link is (http://www.linkebuy.com.br/notebook/detalhe?id=5):

<!-- url() function just completes the right URL (production or development) -->
<a href="<?php echo url('linkebuy/parceiro/?url=' . rawurlencode($l->getUrl()), true) ?>" class="<?php echo $leadClass ?> oferta" target="_blank">
    <?php echo $l->getNomeFantasia() ?>
</a>

When clicked the link redirects to an action (/linkebuy/parceiro), where happens the following (basicly nothing, just keeping in the framework):

public function execute($request, $response) {
    $response->addParameter('url', rawurldecode($request->getParameter('url', ''))); //This creates $url in the view
    $response->setTemplate('site/linkebuy/lead-parceiro.php'); //Forwards to the view
}

It includes the view, lead-parceiro.php (above on the question, I link to this page), where the head contains:

<script type="text/javascript">
    setInterval(function(){ window.location = '<?php echo $url ?>'; },3000);
</script>
like image 265
Ramon K. Avatar asked Mar 06 '13 17:03

Ramon K.


People also ask

How do you access the data sent through the URL with the GET method in PHP?

The data sent by GET method can be accessed using QUERY_STRING environment variable. The PHP provides $_GET associative array to access all the sent information using GET method.

How can I GET URL in PHP?

The necessary superglobal variables such as $_SERVER['HTTPS'], $_SERVER['REQUEST_URI'], $_SERVER['SERVER_PORT'] are used to get full URL in PHP. The variable HTTPS can easily retrieve the protocol in the URL of a webpage. If it returns a value “on”, then the protocol is HTTPS.

How we can pass query parameter in URL?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.


2 Answers

If you can't get rid of the restriction you can pass the url in 2 parts like this

http://www.linkebuy.com.br/linkebuy/parceiro?protocol=http&url=www.google.com

And then parse it on your code to make the full url for the redirect.

like image 187
Ateszki Avatar answered Sep 25 '22 23:09

Ateszki


You should use urlencode when you pass anything as URL parameter

like image 39
RiaD Avatar answered Sep 24 '22 23:09

RiaD