Script to execute code


#21

Oh, okay, here we need to use the " htmlspecialchars() " function to display the code inside of the variable!

<textarea name="code" cols="40" rows="5"><?PHP echo htmlspecialchars($code); ?></textarea><br>


#22

still the same error


#23

Sorry, tested it and it does not work that way here either… Try the highlight function instead…
<textarea name="code" cols="40" rows="5"><?PHP echo highlight_string($code); ?></textarea><br>

From what I just read that should do it for you.


#24

still the same((( so i guess it is not possible to run that code with in one file


#25

Post the entire page you have now and I will play with it for you. If it will not post, send it in a private message.
You can send files in PM’s…


#26
<?PHP
$result = "";
if (isset($_POST['submit'])) {
    $code = $_POST['code'];
    $result = eval($code);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Page</title>
</head>
<body>
<form method="post" action="process.php">
<textarea name="code" cols="40" rows="5"><?PHP echo highlight_string($code); ?></textarea><br>
<input type="submit" value="Submit" />
</form>
    <h3>Results:</h3>
    <?PHP echo $result; ?>
</body>
</html>

it is the whole code I named file process.php , so i could execute it without secod file


#27

This version works for me. Seems you did not have a NAME field in your input clause.
I removed the extra results part and just put the code in place directly using the eval function.
I tested it with this: echo “testing, 1, 2, 3”; AND, it worked as it should. Hope this helps you out…

<?PHP
$code = "";
if (isset($_POST['submit'])) {
    $code = $_POST['code'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test Page</title>
</head>
<body>
<form method="post" action="codetest.php">
    <textarea name="code" cols="40" rows="5"><?PHP echo $code; ?></textarea><br>
    <input name="submit" type="submit" value="submit" />
</form>
<h3>Results:</h3>
<?PHP echo eval($code); ?>
</body>
</html>

Shorter and works as-is… But, it may not work with any complicated codes… Who knows…


#28

and i should name the file codetest.php yes?


#29

No, sorry, that was what I called it. You can name it whatever you want and just put that in the form’s action clause… Sorry… Did it late at night…


#30

working perfectly than you!!


#31

Good for you! You are welcome! Will see you in your next post…