문제

I am trying to do some htmlentities. However, the hyperlinks are now broken due to them being converted to the html codes, wanting to do this as for some stupid reason the university has given us all the same password for the servers.

Last year I almost failed as someone went onto my server and filled with the javascript and css hacks, so this will prevent it, however it's not much use if the hyperlink won't work, so how do I prevent this? Here's the code I have so far for this specific area:

$sub = substr($row['content'],0,300).'.......... <a href="blogpost.php?id='.$row['id'].'">See full article</a>';
echo htmlentities($sub,ENT_QUOTES,"UTF-8");

If anyone can help, it's much appreciated, thanks.

도움이 되었습니까?

해결책 2

Don't apply htmlentities over the whole link, but on the values you actually want to escape, like this

$sub = htmlentities(substr($row['content'],0,300), ENT_QUOTES, 'UTF-8') . '.......... <a href="blogpost.php?id=' . htmlentities($row['id'], ENT_QUOTES,'UTF-8') .'">See full article</a>';
echo $sub;

다른 팁

I think you're applying htmlentities() on too much of your output. Just do it like this:

<?php echo htmlentities(substr($row['content'],0,300)).
           '&hellip;<a href="blogpost.php?id="'.htmlentities($row['id']).'">See full article</a>'; ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top