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 7752633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:50:54+00:00 2026-06-01T11:50:54+00:00

Suppose I have something like this: if ($command === ‘txt’) { header(‘Content-type: text/plain;charset=utf-8’); echo

  • 0

Suppose I have something like this:

if ($command === 'txt') {
    header('Content-type: text/plain;charset=utf-8');
    echo $result;
    exit();
} else ($command === 'js') {
    $json = array( $result );
    header('Content-type: text/javascript;charset=utf-8');
    echo $callback . '(' . substr(json_encode($json), 1, -1) . ');';
    exit();
}

Can I use htmlspecialchars on the echo statements, it messes it up if it’s interpret as html, on the other hand does not having them leave the risk that someone may try doing an xss attack if the browser does interpret it as html.

What should I do? Should I not worry and not htmlspecialchars?

  • 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-01T11:50:56+00:00Added an answer on June 1, 2026 at 11:50 am

    No, you should not use htmlspecialchars. Neither of those would make sense, since htmlspecialchars is intended to avoid HTML injection. However, if you use JSON, your client code needs to take care how it uses the returned value.

    For instance, injecting it into innerHTML would not be safe.

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

Sidebar

Related Questions

Suppose you have something like this: class intlist: def __init__(self,l = []): self.l =
Suppose I have something like this page: <noscript>You need JS for this page</noscript> <script>
Suppose I have something like this: class A { public B mem; public int
I have a route that is suppose to match something like this localhost:3000/site/admin and
Suppose I have a table of users. Something like: ID integer, USER text, POSITION
Suppose I have something like this int strLen; printf(Please enter a number: ); scanf(%d,
Suppose I have something like this: public abstract class AbstractDataObject { public abstract void
Say that I have simple command line application, that looks something like this #
Suppose I have something like this: for (int i = 0; i < 1001;
Suppose I have something like this: <span class=filesize>File<a href=http://example.com/image.jpg target=_blank>image.jpg</a>-(1.61 MB, 1000x1542, <span title=what

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.