What does "&key" means in PHP?

keyword, php

Solution

You need to encode the `&` character with a character reference like `&`:

'<a href="http://www.domain.com/act.php?id=' . $userid . '&amp;key=' . $actkey . '">http://www.domain.com/act.php?id=' . $userid . '&amp;key=' . $actkey . '</a>'

Or better:

'<a href="' . htmlspecialchars('http://www.domain.com/act.php?id=' . $userid . '&key=' . $actkey) . '">' . htmlspecialchars('http://www.domain.com/act.php?id=' . $userid . '&key=' . $actkey) . '</a>'

Problem

I have a very weird problem. I am using PHP, in my PHP code, I wrote the email content and generated this link: ``` .... <a href="http://www.domain.com/act.php?id=' . $userid . '&key=' . $actkey . '">http://www.domain.com/act.php?id=' . $userid . '&key=' . $actkey . '</a> .... ``` Most of the time, it works fine. Then, I receive lots of complaints saying they can't activate. After checking their emails, I found this: ``` <a href="http://www.domain.com/act.php?id=20090=hsdf87hsf89sd">http://www.domain.com/act.php?id=20090=hsdf87hsf89sd'</a> ``` The "&key" is missing. Why? Very weird bug!!! The full PHP command: ``` $content = '<div style="font-family:Calibri; color:#333;"> Hi there, <br><br> Thank you for register to our website, click the following link to activate your account:<br><br> <a href="http://www.domain.com/act.php?id=' . $userid . '&key=' . $actkey . '">http://www.domain.com/act.php?id=' . $userid . '&key=' . $actkey . '</a><br><br> XXX Team</div>'; ``` Gumbo could be right, my email content is HTML-based: ``` $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; ```

Original source