Re: Question about urlencode....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Unless your URL is more complicated than your example, you shouldn't need to 
use urlencode() at all.   You'd need to use it in a case where your string 
may contain characters that aren't valid in URLs like spaces and such:

$baseurl = "http://www.somesearchsite.com/search=";;
$searchfor = "Grace O'Mally";

$searchurl = $baseurl . urlencode($searchfor);

Since you set your URL explicitly and it's not something entered by a user, 
you shouldn't need it.

Try that and see if it fixes your other problem with double encoding.. or at 
least gives a better clue as to where it's coming from.

Slainte!

-TG

----- Original Message -----
From: Colin Guthrie <gmane@xxxxxxxxxxxxxx>
To: php-general@xxxxxxxxxxxxx
Date: Thu, 22 Nov 2007 16:19:18 +0000
Subject:   Question about urlencode....

> Hi,
> 
> OK this one is a little embarrasing. I've been doing this for years and
> I just wonder if I'm wrong....
> 
> Say you have an exit link on your site, e.g. /leave.php, which accepts a
> "url" get arg. You use this page to record stats/whatever and then issue
> a Location: header to take the user to the correct location.
> 
> Fairly standard yeah?
> 
> Well I've been doing something like:
> 
> $url = 'http://colin.guthr.ie/';
> echo '<a href="/leave.php?url='.urlencode($url).'">Click</a>';
> 
> The logic in /leave.php does not need to call urldecode as it's done
> automatically by PHP.
> 
> This has worked well for me in the browsers I've used (IE, FF etc.)
> 
> Recently, though, when using google webmaster tools I noticed that I was
> getting a lot of 404's and this ultimately stemmed from the double
> urlencoding of these url paramaters whereby the % signs used to encode
> characters like / as %2F were encoded themselves leading to %252F. PHP
> would automatically urldecode this to %2F but that still leaves me with
> an encoded variable. Ugg.
> 
> So my question is, is the google bot just getting it wrong? Is it
> reading the link and seeing a % and encoding it? Or is it finding a page
> somewhere randomly on the interweb which has incorrectly double encoded
> it and going from there?
> 
> It doesn't give you an referrer info which makes tracking down such
> errors pretty tricky.... :(
> 
> I could just call urldecode manually, but I'm curious as to why I should
> need to. Anyone fought with this before?
> 
> Col

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux