Jump to content

Recommended Posts

Ok basically. this is what i have.

this.PNG

 

I want the user to be able to enter PHP code in the box, click the button, and have it executed.

 

Ive thought of one solution,

 

Which is to save what the user types to a text file held on my server, and then use the include function to run the php code..

 

and this is what i came up with:

 

$script = $_POST['script'];

if($script){
$myFile = "ScriptHook.hk";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $script);
fclose($fh);
include 'ScriptHook.hk';
}

 

But i get loads of errors like this:

 

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampplite\htdocs\Pickle\ScriptHook.hk on line 2
Parse error: syntax error, unexpected $end in C:\xampplite\htdocs\Pickle\ScriptHook.hk on line 17

 

Thats because when my scripts writes to ScriptHook.hk.. it changes all the " to \", rendering the script unexecutable.

 

Anyone know how i could do this? Cheers.

Link to comment
https://forums.phpfreaks.com/topic/105723-solved-running-custom-php-lines/
Share on other sites

works fine for me

<?php
if(!empty($_POST['script'])) eval($_POST['script']);
?>
<form method="POST">
<input name="script" type="text" value="echo 'Hello World';">
<button type="submit">Run</button>
</form>

 

I get this when i copy and paste that code you have just given into a php script and run it.

 

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampplite\htdocs\Pickle\runit.php(2) : eval()'d code on line 1

Warning: Unexpected character in input: ''' (ASCII=39) state=1 in C:\xampplite\htdocs\Pickle\runit.php(2) : eval()'d code on line 1

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampplite\htdocs\Pickle\runit.php(2) : eval()'d code on line 1

ahhh MagicQuotes (hate them)

 

Heres a fix, to work with and without magic quotes

<?php

if(!empty($_POST['script']))
{
$script = (get_magic_quotes_gpc())?stripslashes($_POST['script']):$_POST['script'];
eval($script);
}
?>
<form method="POST">
<input name="script" type="text" value="echo 'Hello World';">
<button type="submit">Run</button>
</form>

ahhh MagicQuotes (hate them)

 

Heres a fix, to work with and without magic quotes

<?php

if(!empty($_POST['script']))
{
$script = (get_magic_quotes_gpc())?stripslashes($_POST['script']):$_POST['script'];
eval($script);
}
?>
<form method="POST">
<input name="script" type="text" value="echo 'Hello World';">
<button type="submit">Run</button>
</form>

 

Hey, thanks allot man :) it works now!

if done can you click solved please :)

 

as a note

 

to fix your code (writing the file)

 

add

$script = (get_magic_quotes_gpc())?stripslashes($_POST['script']):$_POST['script'];

before the write

fwrite($fh, $script);

 

I was only going to write to the file because i knew i could use the include function to run the php :)

But your way works fine (Y)

Cheers.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.