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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:03:33+00:00 2026-05-12T10:03:33+00:00

In PHP, what is a list of potentially harmful characters that can be used

  • 0

In PHP, what is a list of potentially harmful characters that can be used to break a PHP page? And, using regular expressions, how can I filter out the bad sequence of characters from all of my user input?

For example.. to check if a email is valid I would use the below line:

preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",$email);

This above checks for the specific pattern of the email.

But, just like when you check if a email is Valid using a regular expression, how would I check if the input has any invalid character patterns using one expression for every input? I would like to place this line at the very top of my php page which accepts a $_GET or $_POST to prevent any hacker-like inputs from crashing the page.

Hope this makes sense.
Thank you
PG

  • 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-12T10:03:33+00:00Added an answer on May 12, 2026 at 10:03 am

    There is no “one and only” way of filtering input like you describe, since no input is inherently invalid or even necessarily malicious. It’s entirely what you do with the input that matters.

    For example, suppose you have some text in $_GET['field'] and you are about to compose a SQL query. You need to escape the value using mysql_real_escape_string() (for MySQL, of course) like so:

    $sql = "INSERT INTO some_table (some_field) VALUES ('" . mysql_real_escape_string($_GET['field']) . "')";
    

    This escaping is absolutely crucial to apply to input that you’re using in a SQL query. Once it’s applied as you see here, even malicious input from a hacker will have no ill effects on your database.

    However, this function is both useless and outright wrong to use if you’re including $_GET['field] in some HTML output from your page. In that case, the function htmlspecialchars() is useful. You might do something like:

    echo "<p>Your comments were: " . htmlspecialchars($_GET['field']) . "</p>";
    

    Both these examples are quite safe from “hacker-like inputs.” You will not be inserting malicious data into your database or into your HTML. Yet, notice the two forms of escaping are completely different functions, each suited to its use.

    By contrast, imagine if you tried to “validate” input for these two uses at the same time. You certainly couldn’t allow < or > characters, since those could be part of a malicious HTML attack like Cross-Site Scripting. So, visitors who want to write “I think 1 < 3” would be stymied. Likewise, you couldn’t allow quote marks for fear of malicious SQL injection attacks, so poor “Miles O’Brien” could never fill out your form!

    Proper input escaping is very easy to do, as you use it in different contexts (it’s often even easier than validating input!) yet the results are so much better.

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

Sidebar

Related Questions

In php there is a list of all the parameters you can pass to
I'm creating my own template engine using PHP. The basic idea is that for
I am considering using MongoDB to store documents that include a list of key/value
I have a page called list.php which retrieves from database and shows all the
First of all, let me just say that I'm using the PHP framework Yii,
I have a php/mysql list, where I can display lots of thumbnails. My problem
I want to convert PHP list (array), i.e. array(start, end, coords) into associative array
I have a php file list.php <?php $arr=array('444','555'); echo var_export($arr); ?> Now I want
require_once'modules/logger.php'; $Logger = new Logger(); require_once 'templates/list.php'; $Templates = new templatesList(); require_once 'widgets/list.php'; $Widgets
pls help me how to create a .htaccess file as index.php?regional=aaa domain.com/aaa/ list.php?regional=aaa&ctg=bbb&orderby=ccc&page=123 domain.com/list/aaa/bbb/ccc/123/

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.