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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:26:27+00:00 2026-05-30T10:26:27+00:00

I know finding alternatives to eval() is a common topic, but I’m trying to

  • 0

I know finding alternatives to eval() is a common topic, but I’m trying to do something I’ve not done before. I am processing known-format CSV files, and I have built rules for how the data will be handled depending on the source columns available.

Here is a simplified example of what I’m doing. In this example, $linedata represents a single row of data from the CSV file. $key["type"] points to the column I need the data from. If this column holds the value of “IN”, I want $newcol set to “individual”, else “organization”.

$key["type"] = 12;
$linedata[12] = 'IN';
$rule = '($linedata[($key["type"])] == "IN" ? "individual" : "organization");';
eval ('$newcol = ' . $rule);

So $rule stores the logic. I can run a filter on the $linedata array to try and protect from malicious code coming from the CSV files, but I wonder if there is a better way to store and process rules like this?

  • 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-30T10:26:28+00:00Added an answer on May 30, 2026 at 10:26 am

    You cannot store arbitrary PHP in a CSV file and then expect it to work without calling eval (or similar functionality).

    The safe way to do what you’re asking for is to treat the file as data, not code.

    This is why languages like BBCode exist: you can’t have an inert language trigger active features directly, so you create an easy-to-interpret mini-scripting-language that lets you achieve what you want.

    In other words, you cannot store active “rules” in the file without interpreting them somehow, and you cannot simultaneously allow them to contain arbitrary PHP and be “safe”. So you can either attempt to parse and restrict PHP (don’t, it’s tough!) or you can give them a nice easy little language, and interpret that. Or, better yet, don’t store logic in data files.

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

Sidebar

Related Questions

I know this isn't a unique issue but I've not had much luck finding
I know this is somewhat of a dead horse, but I'm not finding a
I know this is a basic questing but I am just not finding a
Know this might be rather basic, but I been trying to figure out how
I was just finding something on web I come to know that we can
I'm not finding an ORM that does this for .net 2.0 (i know it's
I'm having difficulty finding support on this topic, because I know how to pass
I know this might sound silly but I am finding it hard to understand
I already know how XSS works, but finding out all the many different ways
I know how to force check out for Lists Libraries. But I am not

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.