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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:45:35+00:00 2026-06-06T00:45:35+00:00

Well I’m new to PHP but thinking about these stuff has really confused me

  • 0

Well I’m new to PHP but thinking about these stuff has really confused me these days.

Here is my question in detail:

First the situtation is that I need to transfer the data between clients and the server. Ajax should be used to present the data at clients’ side. At the server side, PHP and MySQL will be used to parse the request, grab the data and then send it back.

Then the problem comes. User data sent from the brower can contain &, %, ‘, “ which may damage the formatted POST request or making database attack. Although we can use JS to detect them, the user is still able to send data bypassing the validation, let alone we cannot simply remove them as they may be useful to the user.

So then I checked my weapon library.
At server side, it turns out that I have too many functions to deal with them:
Apart from regular expessions I have

htmlspecialchars, htmlspecialchars_decode, addslashes, stripslashes
urlencode, urldecode, mysql_escape_string, mysql_real_escape_string

At client side with javascript, I don’t have that many but still have:

escape, unescape

OK. Learning that I have so many weapons is good but…how to choose, combine and use them is really a headache for me.

For example suppose I want to have a product name called:

‘%Hooray%’+&ABC

Well maybe no product will be named like this in real life but let’s use it as an example.

The & mark will break the POST message.
The + may impact ajax parsing.
Single quotes may allow SQL injection.
The % mark may cause problems but I’m not sure if it will.

But I still want that name exactly the same after sending it to the database and fetching it back,
which means, the name in database can be different but its presentation in the brower should be the same.

Well this question may be a little bit too long but hope somebody could share some good experience: how to deal with user input string using those functions?

  • 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-06T00:45:37+00:00Added an answer on June 6, 2026 at 12:45 am

    Before sending your data via ajax, encode them:
    Assuming the data is a javascript array.
    Why an array?
    Because if you have a query already (ex. ‘name=me&foo=b&ar’) how you can solve that ‘b&ar’ that is clearly a value to YOU but ‘b’ and ‘ar’ for the javascript engine?

    for(i in arr)
       { arr[i] = encodeURIComponent(arr[i]); }
    

    This function replaces all harmful url characters (, / ? : @ & = + $ #) and some more.
    Then you can send your query by building up like arr.join('');
    But i’d use jquery and send the array right after.

    On PHP side the basic rule you must obey is that you NEVER save your data without mysql_real_escape_string();

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

Sidebar

Related Questions

Well, I got problem here with opengl ES stuff (just started to learn about
Well, I know there is a lots of posts about it, but I have
Well, I have to revive a question that was answered here before. I've made
Well, this is my first post here and really enjoying the site. I have
Well... simple question, right? But with no so simple answers. In firefox i use
Well I am pretty new to both iphone and PHP development, and am trying
Well, the eBay SDK has a pretty nice selection of examples, but they are
Well this question and this question are similar but no answers that work. In
Well, not random, because its the same every time, but #include<iostream> using namespace std;
Well, for integers I would use NSNumber . But YES and NO aren't objects,

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.