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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:39:24+00:00 2026-06-01T08:39:24+00:00

I would like to make something like tryruby.org . I take a line from

  • 0

I would like to make something like tryruby.org. I take a line from the user (e.g., echo __FILE__) and I want to execute it in PHP and return the output back to the client.

I tried to do exec('php -r ' . $command, $output), but $output always contains the PHP help section.

How can I implement this feature?

  • 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-06-01T08:39:25+00:00Added an answer on June 1, 2026 at 8:39 am

    It looks like your problem is that you aren’t wrapping your code to be executed with ' '. You also need to be wary of ' in the code, special characters, escape sequences, etc.

    In fact, if you insist on using exec(), it might be better to do this (to completely avoid having to worry about escaping and the such):

    $command = base64_encode($command);
    exec("php -r 'eval(base64_decode(\"$command\"));'", $output);
    

    You could use eval() instead of what you’re posting above.

    The main issue here (both with eval() and your exec() code) is that taking PHP code from user input simply isn’t safe:

    The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.

    Suggestion

    Since you want to return the result of the PHP code, you could potentially do something cool with Ajax, where you pass the PHP code to a script (Base64 encoded, perhaps) as a parameter:

    $code = base64_decode($_GET['code']);
    // Clean the user input here
    eval($code);
    

    Ajax example using jQuery:

    // assuming `code` contains the PHP code
    var encoded = base64_enc(code);
    
    $.get('execute.php?code=' + encoded, function(data) {
        var result = new String(data);
        // do something with the result here, such as displaying it
    }, dataType='text');
    

    For Base64 encoding in JavaScript, see this.

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

Sidebar

Related Questions

I would like to make my application ask the user some informations via something
For example, if I make a query like between(1,4,X)? I would expect something like
Hello :) i would like to ask, if it's posible to make something like
I would like to make use of something like the 3 circles at the
On my personal website, i would like to make it pronounce something I solved
I have many FrameworkElements (TextBlock, CheckBox, ListBox..) and I would like to make something
I would like to make something like this: @profiles #(I think in Java, so
I would like to make something like Add to favorites technology. In my app
I would like make an extension method for the generic class A which takes
Would like to make anapplication in Java that will not automatically parse parameters used

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.