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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:43:03+00:00 2026-05-27T17:43:03+00:00

EDIT: after reading all the input from the other users, i decided, to use

  • 0

EDIT: after reading all the input from the other users, i decided, to use what @chris suggested call_user_func_array() one more reason not to use eval() its slower than call_user_func_array(), but so far, nobody was able to exploit it my way, if you find a way, please post it as answer or comment :). So everybody can learn from it.
Merry XMAS to all!

—EDIT END—

Ok i needed to make a dynamic code:

I get user input like $_POST[‘a’], $_POST[‘b’]; // Depends on each query how many user input.

$sql = "SELECT 1, 2, 3 FROM x WHERE b = ? AND a = ? LIMIT 10"; // SQL STATEMENT
$input = array($_POST['a'], $_POST['b']);
$output = 3; // Number of variables need for 1, 2, 3
$data = readDB2($sql, $input, $output);
var_dump($data);

this input, gets passed to mysqli->prepared statements

cause the number of variables is dynamic ($input and $output);

i used the php function eval(); Now my question can this be exploited, in my code?

Just look in my function readDB2 to see how i used the eval() function (used it 3x times).

public function readDB2($sql, $input, $output1) {

    $stmt = $this->mysqli->prepare($sql);
    if(!empty($input) && is_array($input)) {
        $sp = "";
        $data = "";
        $inputn = count($input) - 1;
        for($i = 0; $i <= $inputn; $i++) {
            if($i !== $inputn) {
                $data .= '$input[' . $i . "],";
            } else {
                $data .= '$input[' . $i . "]";
            }
            $sp .= "s";
        }
        $bind = '$stmt->bind_param(\''. $sp . '\',' . $data . ');';
        eval("return $bind");
    }
    if (!$stmt) {throw new Exception($this->mysqli->error);}
    $stmt->execute();
    if (!$stmt) {throw new Exception($this->mysqli->error);}
    $stmt->store_result();
    $checker = $stmt->num_rows;
    if($checker !== 0) {
        if(!empty($output1)) {
            $out = "";
            for($i = 1; $i <= $output1; $i++) {
                if($i !== $output1) {
                    $out .= '$out' . $i . ",";
                } else {
                    $out .= '$out' . $i;
                }
            }
            $res = '$stmt->bind_result(' . $out . ');';
            eval("return $res");

            $vars = "array(" . $out . ");";

            while ($stmt->fetch()) {
                $results[] = eval("return $vars");
            }

        }
    } else {
        $results = "NO RESULTS";
    }
    $stmt->fetch();
    $stmt->close();

    $this->results = array('num_rows' => $checker, $results);

    return $this->results;
}

EDIT FOR meagar

$bind = '$stmt->bind_param(\''. $sp . '\',' . $data . ');'; 
==
$bind = '$stmt->bind_param('ss', $input[0], $input[1]);); 
OR and so on
$bind = '$stmt->bind_param('sss', $input[0], $input[1], $input[2]););

EDIT FOR Incognito:

$input = array($_POST['pwnd']);

$data = readDB2($sql, $input, $output) {

public function readDB2($sql, $input, $output) {
    ...
    $inputn = count($input) - 1;
    for($i = 0; $i <= $inputn; $i++) {
            if($i !== $inputn) {
                $data .= '$input[' . $i . "],";
            } else {
                $data .= '$input[' . $i . "]";
            }
            $sp .= "s";
        }
        $bind = '$stmt->bind_param(\''. $sp . '\',' . $data . ');';
        eval("return $bind");

    ...
}

in my result

$bind = '$stmt->bind_param(\''. $sp . '\',' . $data . ');';

gets

eval("return $bind");

gets

$stmt->bind_param('s', $input[0]);

not what you said.

  • 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-27T17:43:03+00:00Added an answer on May 27, 2026 at 5:43 pm

    fyi, call_user_func_array() is how you call functions with unknown number of arguments.

    array_unshift($input, str_repeat('s', count($input)));
    $callable = array($stmt, 'bind_param');
    call_user_func_array($callable, $input);
    

    array_unshift() pushes the ‘sss’ string element to the front of the array(we want the front because it needs to be the first argument fed to bind_param)

    $callable is the callback psuedo type

    also, in the future, if you find yourself using eval, familiarize yourself with php’s var_export() function which can assist you with constructing safe strings. Try not to use eval though.

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

Sidebar

Related Questions

What is Lazy Loading? [Edit after reading a few answers] Why do people use
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
EDIT: after reading the answers below and looking at all the guides i am
Is there a way to convert from System.Windows.Forms.HtmlElement to mshtml.IHTMLElemenet3? --edit after answer accepted
edit: many thanks for all the answers. Here are the results after applying the
MAJOR EDIT: Problem was solved after reading Will Dean's comment. The original question is
I've read on SO (and from other websites found on Google after I tried
Edit 3 After reading a boat load I really don't think with any ORM
Edit: Added bounty because I'm seeking an MVC3 solution (if one exists) other than
This is def a newb question but after reading trough all the resources out

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.