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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:19:41+00:00 2026-05-22T21:19:41+00:00

Do I need to escape/sanitize the following? $_SERVER[‘HTTP_USER_AGENT’] in a PHP script (not inserted

  • 0

Do I need to escape/sanitize the following?

  1. $_SERVER['HTTP_USER_AGENT'] in a
    PHP script (not inserted into
    database or displayed to user), for
    example:

    if ($_SERVER['HTTP_USER_AGENT']==$xyz) {
            echo "Congrats, you are using XYZ browser";
    } else {
            echo "You are not using XYZ browser.";
    }
    
  2. $_SERVER['HTTP_USER_AGENT'] when
    placed as a session variable, for
    example:

    $_SESSION['userAgent']=$_SERVER['HTTP_USER_AGENT']
    
  3. Anything that is going to be hashed,
    for example:

    hash('sha512',$randomDataPostedByUser)
    
  4. User input destined for email body
    (in other words, I’ve already taken
    care of email header injections).

If any of the above do need to be excaped/sanitized, what is the best method for each case?

  • 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-22T21:19:42+00:00Added an answer on May 22, 2026 at 9:19 pm

    No, there is no need for sanitation in any of the examples you show, with the following very rare exception for the mail body example:

    (Windows only) When PHP is talking to a SMTP server directly, if a full stop is found on the start of a line, it is removed. To counter-act this, replace these occurrences with a double dot.

    However, you may need to sanitize the session variable later, depending on what you are going to do with it.

    Other notes:

    • Your first example doesn’t seem to make sense, because user agent strings vary heavily. You will have to use strstr() or regular expressions to match user agents.

    • Storing the user agent in a session variable might not be a good idea if you’re doing comparisons – just pull it from the $_SERVER array when you need it.

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

Sidebar

Related Questions

I'm generating an XML document from a PHP script and I need to escape
I need a method in JavaScript to escape all characters which are not (
Do I need to escape backslash in PHP? echo 'Application\Models\User'; # Prints "Application\Models\User" echo
New to PDO - do I need to escape arguments I'm passing into a
Which characters need to be escaped before being inserted into a JET Engine data
I need to escape entire javascript code block using escape() compatible function via PHP,
I have the following sql command, i need to escape parentheses in PostgreSQL, how
What do I need to do to properly sanitize/escape a parameter that is being
Could you please tell me how can one escape an apostrophe. I need it
Need to locate the following pattern: The letter I followed by a space then

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.