I see why this below is bad and that htmlspecialchars must be used to prevent some xss vulnerabilities:
<?php $url = '<plaintext>';
echo $url;?>
like so:
<?php $url = '<plaintext>';
htmlspecialchars($url, ENT_QUOTES, "UTF-8");
echo $url;?>
In my database i store the filename only which is user provided. (im sure this will change as i learn more about this subject)
What im wondering though, is if this below is actually doing anything to protect against XSS? Is it less of a vulnerability compared to the previous case?
I've tried injecting script tags with and without htmlspecialchars and it seems to do nothing in either case. The script code wont execute.
Is it secure? Is htmlspecialchars the right tool for the job? How can i make it better?
$sql['image'] is fetched from my database and this below is the code that displays the image.
<?php $url = "/images/" . $sql['image'] . ".jpg";
$url = htmlspecialchars($url, ENT_QUOTES, "UTF-8");?>
<img src="<?php echo $url;?>">
outputs:
<img src="/images/test.jpg">