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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:37:31+00:00 2026-05-25T18:37:31+00:00

I am making a function so that I can post from Ajax using a

  • 0

I am making a function so that I can post from Ajax using a general function where I just pass the params, to avoid having to create one php file for each Ajax function.

This is how my function looks right now in the PHP side after receiving, via post, the params that you can see in the code:

$class_name = $_POST['class_name'];
$function_name = $_POST['function_name'];
$params = "'" . implode("','", $_POST['params']) . "'";
$model = new $class_name();

//Apply the function
echo $model->$function_name($params);

It is working except from the part of the params… PHP is interpreting it as one param, what can I do so that $params is not intepreted as a single string?

  • 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-25T18:37:32+00:00Added an answer on May 25, 2026 at 6:37 pm

    The third line actually makes $params a single string containing all the params.

    Depending on your framework (and how you’re passing the params in your Ajax stuff), you might be able to pass $_POST['params'] as is to the method, rather than passing $params. In which case you don’t need to build the string at all.

    If you need to call a function that expects the params to be passed individually, instead of in an array like that, try

    call_user_func_array(array($model, $function_name), $params)
    

    If $params contains 1, 2, and 3, and $function_name is ‘foo’, the above expression would be equivalent to $model->foo(1, 2, 3).

    Note, this will let people call any public method of any class that’s available to your script. You need some kind of access control in order to keep people from running random stuff. As suggested in the comments on your question, a whitelist of some kind (even if it’s just a member variable that says whether the class was meant to be used by random code like this) would go a long way toward preventing security issues.

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

Sidebar

Related Questions

When making a function call in Linux (or OS X for that matter), can
I am making a page that accepts post data from any number of pages
i am making an upload with Ajaxupload plugin and i am using this function
I've got an html page from where Im making this call periodically: function logon(id)
I'm having a little bit of trouble making OpenID work from within an iframe.
I'm making a mailing list script that takes advantage of ajax (async=false) to send
Here's my scenario. I call jqModal using its ajax functionality that displays a form
I'm making a function for my users where they can upload large XML files
Hi guys i am retrieving data from php using ajax , what i am
Im making firefox extension. One function stores value in every tab, to use it

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.