开发者

Ampersand using Javascript & PHP

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

开发者_如何学C
$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


Escape the URL first:

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


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.


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>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜