views:

187

answers:

3

I'm trying to redirect a page using javascript output using php. The problem I'm having is passing the ampersand as you can see below.

Input

$url = 'number=1&id='.$usrid->id;

echo "<script type='text/javascript'>
    window.location = 'directory?$url';
    </script>";

Output

The above return on browser address bar this:

http://www.domain.com/directory/?number=1#038;id=190
A: 

Use the html_entity_decode function

$url = 'number=1&id='.$usrid->id;

echo "<script type='text/javascript'>
window.location = 'directory?".html_entity_decode($url)."';
</script>";
null
He needs to escape not decode.
Ollie Saunders
A: 

Resolution to the above issue exactly as 'yar' suggests. The redirect was happening too fast and the php script didn't stop early. A simple exit function fixed the issue after redirect code.

Codex73
Huh? If you were getting the #038; in your URL then you should have needed to do as per my answer.
Ollie Saunders
+1  A: 

Escape the URL first:

$url = htmlspecialchars('number=1&id=' . $usrid->id);
Ollie Saunders