11

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>
7
  • Use simple urlencode() and tell us if that makes any difference. Commented Mar 6, 2013 at 17:35
  • No difference at all. Commented Mar 6, 2013 at 17:36
  • 2
    The problem is in your redirect function....show us the code ;) Commented Mar 6, 2013 at 17:37
  • http%3A%2F%2Fgoogle.com is urlencoded Commented Mar 6, 2013 at 17:37
  • 1
    I think is probably an apache config restriction not allowing to have http:// on your querystring Commented Mar 6, 2013 at 18:04

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

4 Comments

YEAH! You're right! How can I get this fixed? I mean, fix the apache config.
I'm not sure, this is probably a rewrite rule cheking your querystring. Look at the .htaccess files and the apache conf files to find it.
Have a look at this answer, as your site is at hostgator, the accepted answer must be relevant stackoverflow.com/questions/10992219/…
For those who are searching for an alternative answer, you can base64_encode the URL and base64_decode it later.
5

You should use urlencode when you pass anything as URL parameter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.