开发者

Ampersand using Javascript & PHP

开发者 https://www.devze.com 2022-12-09 02:35 出处:网络
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.

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

精彩评论

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