Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:30:14+00:00 2026-06-18T09:30:14+00:00

I see why this below is bad and that htmlspecialchars must be used to

  • 0

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">
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:30:15+00:00Added an answer on June 18, 2026 at 9:30 am

    In principle you can’t trust any user input, ever. If $sql['image'] will directly or indirectly be provided by users, then it won’t matter if you add constants to the beginning and end of that string. Either way you’ll have to rely on htmlspecialchars() not containing any bugs that would allow scripting to be injected.

    To actually increase security in this case, you’d have to take somewhat more drastic measures. One popular method for that would be to simply assign file names yourself, for example by hashing on the contents of the file and using that hash instead of the original file name to store the file. md5() and sha1() tend to come in handy for that.

    Also, assuming the users provide the images whose file names you’re storing, you’d have to make sure those can’t be used to get the job done, either. For example, the users might upload an SVG with an embedded script instead of a JPEG, thus potentially completely avoiding any validation or mangling on the file name itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See this Image below http://i46.tinypic.com/2pt6jkn.jpg This is report in SSRS as shown when it
I have this code below. As you can see I am passing two variables
I have this edmx model (see below) and I would like to add an
See code below: I want Page 1 to alert #testing... This works in C
UPDATE (spoiler): This question is answered (see David Carlisle answere below) and it looks
Please see the back trace below, I don´t think I have seen this before
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
This question was initially misphrased, see the EDIT below. I'll leave it up for
Suppose that I have below code: <?php $html = ' <form id=formA> <!-- Form
Ok I have some code that boils down to a pattern like this class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.