--- Jordi Canals <[EMAIL PROTECTED]> wrote:
> I have seen an strange thing with the funcion
> Header("Location: $url") and will tell in short words.
> 
> I have a method in a class wich composes an URL from the
> database, this method sets some extra params in the url. In
> this case, the function returns:
> 
> /myaccount/?opt=sys&amp;id=3
> 
> Note the &amp; in the URL
> 
> Well, with this code, the url works perfect and the &amp; is
> going as expected redirecting to /myaccount/?opt=sys&id=3
> 
> echo '<a href="'. $url .'">Test URL</a>';

There is no redirection taking place here. HTML entities are interpreted
by the browser. In fact, this is their whole purpose - for representing
characters properly in HTML.

> But when triying 
> 
> header("Location: $url");
> 
> What I get is address is literally the &amp; string and not the
> & char.

Yes, because when you use header(), you're setting a raw HTTP header. This
is not to be confused with HTML, which is included in the content of an
HTTP response.

> header('Location: '. html_entity_decode($url));
> 
> I would like to know if there is a better way to do it

This should work fine. However, I would prefer to keep the data in its
original format and only use htmlentities() when I plan to display it
within HTML, leaving it unaltered otherwise.

Hope that helps.

Chris

=====
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
     Coming December 2004
HTTP Developer's Handbook - Sams
     http://httphandbook.org/
PHP Community Site
     http://phpcommunity.org/

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

Reply via email to