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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:25:03+00:00 2026-05-17T23:25:03+00:00

I am making a replication website ( replicating codingbat.com ), And I have been

  • 0

I am making a replication website ( replicating codingbat.com ), And I have been designing it all day and I have to a halt where I need to decide to go with Either a Java Backend or PHP Backend. I have a Java one done already but it just doesnt seem like it is very productive and secure:

 <?php

include ("/var/www/challenges/challenges/java/java.class.php");

function getChallenge()
{
    return new JavaIntroIIIChallenge();
}

class JavaIntroIIIChallenge extends JavaChallenge
{
    public $abbas = array();
    public function __construct()
    {
        $this->abbas = $this->getABBAs();
        parent::__construct1(3, "public static void printABBA(String a, String b) {\n\n}\n",
            $this->getStringLiteral($this->abbas));
    }

    public function getStringLiteral($abbas) {
        $return = "";
        foreach ($abbas as $ab){
            $return .= $ab[0] . ":" . $ab[1]. " ";
        }
        echo $return;
        return $return;
    }

    public function getABBAs()
    {
        $array = array();
        $array1 = array("x" , "y", "Hello" , "a" , "b", "c" , "5", "t");
        $array2 = array("y" , "x", "CodeMeh" , "b" , "c", "a" , "0", "z");
        $rand = array_rand($array1, 5);
        return array(array($array1[$rand[0]], $array2[$rand[0]]), array($array1[$rand[1]], $array2[$rand[1]]), array($array1[$rand[2]], $array2[$rand[2]]),array($array1[$rand[3]], $array2[$rand[3]]),
            array($array1[$rand[4]], $array2[$rand[4]]));
    }

    public function getFullCode($cName, $subCode)
    {
        return "public class $cName {\npublic static void main(String[] args) {System.out.println(\"HELLO\");for(String arg:args){System.out.println(\"HELLO\");String[] ab = arg.split(\":\");printABBA(ab[0], ab[1]);}} $subCode }";
    }

    public function getResults($output)
    {
        $results = array("success" => false);

        if (empty($output))
        {
            $results['success'] = false;
        } else
        {
            $count = 0;
            $index = 0;

            foreach ($output['output'] as $line)
            {
                $string = $this->abbas_literal[$index][0] . $this->abbas_literal[$index][1] . $this->abbas_literal[$index][1] . $this->abbas_literal[$index][0];
                //echo $string . "123";
                if (strtolower($string) == strtolower($line)){
                    $results['tr'][$index]['expected'] = $string;
                    $results['tr'][$index]['thisrun'] = $line;
                    $results['tr'][$index]['ok'] = "&#10003;";
                    $results['tr'][$index]['color'] = "green";
                    $count++;    
                } else {
                    $results['tr'][$index]['expected'] = $string;
                    $results['tr'][$index]['thisrun'] = $line;
                    $results['tr'][$index]['ok'] = "X";
                    $results['tr'][$index]['color'] = "red";
                }

                if($index == 4) {
                    break;
                }

                $index++;
            }
            if($count == 5){
                $results['success'] = true;
            }
        }
        return $results;
    }

    public function printSolution()
    {
        return "<p><div align=left><code>public static void printHelloWorld() {<br><p>System.out.println(\"Hello world!\");</p><br>}<br></code></div></p>";
    }

    public function getDescription()
    {
        return $this->desc;
    }
}

?>

    <?php

    include ("/var/www/challenges/challenges/base.class.php");

    abstract class JavaChallenge extends BaseChallenge
    {

        private $code = "";
        private $args = array();

        public function __construct($id, $code)
        {
            parent::__construct($id);

            $this->code = $code;

        }

        public function __construct1($id, $code, $args)
        {
            parent::__construct($id);

            $this->code = $code;
            $this->args = $args;

        }
        /**
         * Prints the body of the challenge
         */
        public function printBody()
        {
            $cName = "c" . $this->id . "_" . rand(0, getrandmax());

            if (!$this->isFinished())
            {
                //<div class="windowbg"> <span class="topslice"><span></span></span>
                if (isset($_POST['purchase']))
                {
                    if (purchase("Solution for " . $this->name, "You purchased the solution to " . $this->
                        name, $this->points * 2))
                    {
                        $this->message("You purchased the Solution!", $this->printSolution());
                    } else
                    {
                        $this->message("Insufficient funds!", "Unable to purchase this item!");
                    }
                }

?>
 <div class="sp_block">
  <div>
   <center>
   <?php

                if (isset($_POST['code']))
                {
                    $code = $_POST['code'];
                    $output = $this->getOutput($cName, $code);
                    if (!$output['error'])
                    {
                        $results = $this->getResults($output);

?>
   <table width="50%" border="2">
    <tbody>
     <tr>
      <th>Expected</th>
      <th>This Run</th>
      <th></th>
      <th></th>
     </tr>
     <?php

                        foreach ($results['tr'] as $row)
                        {
                            echo "<tr><td> " . $row['expected'] . "</td><td><pre>" . $row['thisrun'] .
                                "</pre></td><td>" . $row['ok'] . "</td><td bgcolor=" . $row['color'] .
                                ">&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>";
                        }

?>
    </tbody>
   </table>
   <?php

                        if ($results['success'])
                        {

?>
    <img width="30" height="30" src="http://www.codemeh.com/forums/Themes/default/images/tick.png"><font size="+2">+<?php

                            echo $this->points;

?> Points</font>
   </center>
   <?php

                            $this->award();
                        }
                    } else
                    {
                        $this->message("Error!", $output['problem']);
                    }
                }

?><br /><br />
  </div>
  <center>
   <span style="font-size:16px">
   <?php

                echo htmlspecialchars($this->getDescription());

?></pre>
   </span><br>
   <br>
            <div style="width: 85%;" align="right"><form method="post"><input name="purchase" value="Purchase The Solution (<?php

                echo $this->points * 2;

?> Points)" type="submit" /></form></div><br />
   <form method="post">
    <script language="javascript" type="text/javascript" src="***"></script> 
    <script language="javascript" type="text/javascript">
                                            editAreaLoader.init({
                                              id : "code"    // textarea id
                                              ,syntax: "java"      // syntax to be uses for highgliting
                                              ,start_highlight: true    // to display with highlight mode on start-up
                                            });
                                            </script>
    <textarea id="code" name="code" rows="30" cols="100"><?php

                echo isset($_POST['code']) ? $_POST['code'] : $this->code;

?></textarea>
    <br>
    <input type="submit" />
   </form>
  </center>
 </div>

<?php

                //<span class="botslice"><span></span></span> </div>
            } else
            {
                $this->message("Error!", "You have already finished " . $this->name . ".");
            }
        }

        /**
         *  Gets the final output of the code.
         */
        public function getOutput($name, $code)
        {
            global $SSH;
            $ssh = ssh2_connect('127.0.0.1', 22);
            ssh2_auth_password($ssh, 'root', '***');
            echo $ssh;
            $output = array('error' => false, 'problem' => "", 'output' => array());
            $full = $this->getFullCode($name, $code);
            $write = file_put_contents(JAVA_SOURCE_FOLDER . $name . ".java", stripslashes($full));
            if ($write)
            {
                //$javac = ssh2_exec($ssh, "javac -d " . JAVA_COMPILED_FOLDER . " " .
                //  JAVA_SOURCE_FOLDER . $name . ".java");
                // exec a command and return a stream
                $javac = getData(ssh2_exec($ssh, "javac -d " . JAVA_COMPILED_FOLDER . " " .
                    JAVA_SOURCE_FOLDER . $name . ".java"));
                if (strlen($javac) == 0)
                {
                    $cd = "cd " . JAVA_COMPILED_FOLDER;
                    $chmod = "chmod 755 " . $name . ".class";
                    $java = "java -Xmx50M -Djava.security.manager -Djava.security.policy==" .
                        JAVA_HOME_FOLDER . "my.policy " . $name . " ";
                    if (!empty($this->args))
                    {
                        foreach ($this->args as $arg)
                        {
                            $java .= $arg . " ";
                        }
                    }
                    $data = getData(ssh2_exec($ssh, "$cd\n$chmod\n$java"));
                    if (strlen($data) > 0)
                    {
                        $output['output'] = explode("\n", $data);
                    } else
                    {
                        $output['error'] = true;
                        $output['problem'] = "Nothing was printed.";
                    }
                } else
                {
                    $output['error'] = true;
                    $output['problem'] = "Compilation error: $javac.";
                }
            } else
            {
                $output['error'] = true;
                $output['problem'] = "File contents = $write, So the file was not able to be written.";
            }
            return $output;
        }

        public abstract function getDescription();

        /**
         * Gets the results of the output.
         */
        public abstract function getResults($output);

        /**
         * Gets the finished compilable code.
         */
        public abstract function getFullCode($cName, $subCode);
    }

?>

That is the current PHP version… It looks very sloppy to me and that is the nicest I can make it… So I wanted to know your opinion, Should I go with a Java backend and make the Java application print out some HTML? Or should I continue with the PHP backend?

I am sorry I cannot explain better, I can barely explain it myself…

  • 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-17T23:25:04+00:00Added an answer on May 17, 2026 at 11:25 pm

    Yes, your code is fairly sloppy. You’re mixing together your HTML, your business logic, and even some code that should be in libraries or helper functions, but that’s what you get when you don’t use a PHP framework. I find that a proper MVC framework makes my PHP code just as readable as anything you can find in Python or Java. Have a look at CodeIgniter or Kohana.

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

Sidebar

Related Questions

I have been making a little toy web application in C# along the lines
I've been making a concerted effort to improve my javascript skills lately by reading
Making echo of a question around the web: Is the syntax for svn:ignore patterns
When making changes using SubmitChanges() , LINQ sometimes dies with a ChangeConflictException exception with
After making some changes in my models (eg. new field in a model and
After making a few modifications to a rails app I am tinkering on, railroad
Im making a small python script to upload files on the net. The script
I am making a simple game in order to learn a new language. I
I'm thinking about making a networked game. I'm a little new to this, and
I'm making a WinForms app with a ListView set to detail so that several

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.