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

  • SEARCH
  • Home
  • 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 6616473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:35:12+00:00 2026-05-25T20:35:12+00:00

What is the preferred order for escaping characters? For instance in PHP environment: 1)

  • 0

What is the preferred order for escaping characters?

For instance in PHP environment:

1) shell -> database = return escapeshellcmd(mysqli_real_escape_string($string));?

2) database -> shell = return mysqli_real_escape_string(escapeshellcmd($string));?

3) No difference at all?

Update

Just to clarify, the website I’m currently trying to fix, contains a lot of old, deprecated functions, uses magic_quotes and is basicly, unusable after the transfer from old host to current one, where the problems arose.

First problem was MySQL escaping, that I fixed with mysql_real_escape_string();, but, still the problem with CLI/Socket MySQL connection environment persists. That is, when you have a value inside a textarea that refers to a UNIX command, preceded by a / – forward slash symbol and you post it- Apache results in 501 Method Not Implemented.

So yes, I have to escape mysql, and escape shell commands. But, the shell command escaping (with example no. 1 from original question) resulted in UTF-8 character braking and losing lots of needed HTML symbols.

The content that needs to be escaped comes out of an WYSIWYG editor (SPAW), therefore it contains lot of quotes and from time to time a UNIX command, that resembles our nations – Latvia – currency. “/ls”, where LS is the currency.

The website is updated by client itself, not a tech person and it has to stay that way- I mean, we cannot take over the content editing. Plus, while we could tell them not to use /ls the UNIX problem persists if, for example, they accidentally get to /mkdir what could resemble an identificator of something.

They are an active travel company, therefore this needs to be fixed ASAP. Since we overtook their website, they are aware that the system is broken, but they don’t have free money at the moment to spend on a new website/fixing current one. Where we have made a conclusion that fixing it would be harder, therefore more expensive than to move over to our CMS, but money is still money.

So, how do I escape shell and database commands from this WYSIWYG editor’s textarea, that is a single string, but, while preserving UTF-8 encoding of our Latvian alphabet letters – ā, š, č, ž etc.?

Maybe I don’t have to escape both, that’s why I’m asking.

Thanks in advance!

Update

On Shrapnels’ request, an example string (copied from SPAW’s HTML view) that would cause Apache to respond with 501:

<div>
    <span style="color: rgb(0, 0, 128); " class="Apple-style-span">
        <span style="font-size: 12px; " class="Apple-style-span">
            /ls
        </span>
    </span>
</div>

SPAW automatically adds all these dumb elements, and yes, if /<command> is inside the string, 501!

And that’s all what it takes to halt, just a namespace referring to a UNIX command line function. Like in this case /ls, but could be /rmdir, /mkdir etc. You could have 20000 symbol stuff there with no /ls and it’ll work. Once there is something like this – bam, dead!

There was originally a function that was meant to clear all the errors (at least I suppose so, it’s original name was – removeShit();):

$string = $_POST['wysiwyg_textarea']; // SPAW text area

function removeStuff($string){
    return str_replace('/wysiwyg/empty.html', '', $txt);
}

The file /wysiwyg/empty.html is 0 bytes- completely empty file.

But this doesn’t cure the mysql escaping and/or UNIX shell command recognition. Therefore, I need a fix to escape the UNIX commands and any MySQL harmful stuff.

So, I was trying to do it with:

return escapeshellcmd(mysqli_real_escape_string($string));

But this one strap out all the utf-8 characters, plus, all the new line symbols got converted to simple string “rn” from, I’d guess \r\n.

And now I’m looking for a function to escape MySQL and Shell cmd`s in one, because I cannot think of another way how to cure all this mess.

  • 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-05-25T20:35:12+00:00Added an answer on May 25, 2026 at 8:35 pm

    Neither.

    Use either escapeshellcmd() or mysqli_real_escape_string(), depending on what you are planning to do with $string.

    Never use both at the same time. It wouldn’t make sense.

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

Sidebar

Related Questions

My current preferred C++ environment is the free and largely excellent Microsoft Visual Studio
What is the preferred way to remove spaces from a string in C++? I
Is there a preferred way to handle animation when using Flex -- For instance,
I am trying to get the users preferred language. I see all kinds of
According to the requirement we have to return a collection either in reverse order
I have generic list which must be a preserved order so I can retrieve
Preferred languages : C/C++, Java, and Ruby. I am looking for some helpful books/tutorials
.NET Framework: 2.0 Preferred Language: C# I am new to TDD (Test Driven Development).
I've always preferred to use long integers as primary keys in databases, for simplicity
What is the preferred way to open a URL from a thick client application

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.