PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 10, 2022

[FIXED] Convert string which retrieve from database in a If condition

 January 10, 2022     database, expression, php, yii     No comments   

Issue

I have stored some rules/logic in a column in database. With that retried rule I want to make it a condition. Since the retrieved rule is returning as string value my condition gives me TRUE for always.

let's say

$www = $rule->logic; // $rule ->logic = (20 >  3) and (20 <  5)
    if($www ){                          
        $this->logger->debug('commision granted');
            }else{
        $this->logger->debug('commision noooo');
            }

However If I simply use if ((20 > 3) and (20 < 5)) Then I can get a correct answer. I have no idea how to convert $www ?


Solution

You can use PHP eval() to execute expression:

$www = $rule->logic; // $rule ->logic = (20 >  3) and (20 <  5)
if(eval("return $www;")){                          
    echo 'commision granted';
        }else{
    echo 'commision noooo';
        }


Answered By - B. Desai
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing