Jump to content

Need help with fake Command prompt


patawic

Recommended Posts

I am currently creating a fake Command prompt for a website but i am stuck.

http://xboxgamercard.net/cmd/

 

If i insert 1 message it shows this

20iz7n9.png

But if i insert a second message it merges the 2 messages together

2cse0q1.png

 

I need to make it so that on the second message it doesnt say ''test' test' but so it only says 'test'

 

Heres the code im using too submit it.

<?php
$msg = $_GET['text'];
$msg = str_replace("Microsoft Windows [Version 6.1.7600]", "", $msg);
$msg = str_replace("Copyright (c) 2009 Microsoft Corporation.  All rights reserved.", "", $msg);
$msg = str_replace("is not recognized as an internal or external command,operable program or batch file.", "", $msg);
$msg = str_replace("\\", "", $msg);
$msg = str_replace("C:WINDOWS>", "", $msg);
$msg2 = "
'$msg' is not recognized as an internal or external command,
operable program or batch file.

C:\WINDOWS>";
$fn = "text.txt"; 
$file = fopen($fn, "a"); 
fwrite($file, "$msg2"); 
fclose($file); 
?>

Link to comment
Share on other sites

You will never be able to determine the "new" input using regular expression. You can probably come close, but I would juse use an index value on each submission.

 

 

The following code is modified from your to just use a form instead of writing to a file as I don't know how you were using it for display. But, this shoudl get you in the right direction.

 

<?php

function stripslashes_deep($value)
{
    $value = is_array($value) ?
                array_map('stripslashes_deep', $value) :
                stripslashes($value);
    return $value;
}

if (get_magic_quotes_gpc())
{
    $_GET = stripslashes_deep($_GET);
}

if (!isset($_GET['idx']))
{
    $idx = 115;
    $text  = "Microsoft Windows [Version 6.1.7600]\n";
    $text .= "Copyright (c) 2009 Microsoft Corporation.  All rights reserved.\n";
}
else
{
    $idx = $_GET['idx'] + 3;
    $input = $_GET['text'];
    $text = substr($input, 0, $idx);
    $user_input = substr($input, $idx);
    $text .= "\n'{$user_input}' is not recognized as an internal or external command,\noperable program or batch file.\n";

}

$text .= "\n";
$text .= "C:WINDOWS>";
$idx = strlen($text);

//echo strlen($text);
//$fn = "text.txt";
//$file = fopen($fn, "a");
//fwrite($file, "$msg2");
//fclose($file);

?>
<html>
<style>
body{ background-color:#000000;color:#ffffff }
textarea { background-color:#000000; color:#ffffff;
           width:100%; height:400px; }
</style>
<body>
  <form method="GET">
    <textarea name="text"><?php echo $text; ?></textarea>
    <input type="text" name="idx" value="<?php echo $idx; ?>">
    <button type="submit" name="submit">Submit</button>
  </form>
</body>
</html>

Link to comment
Share on other sites

I ran your code twice replacing the POST with $msg='xxxxxxxxxxxxxxxxxxxxxxxxx';

 

This is what I got.

 

'xxxxxxxxxxxxxxxxxx' is not recognized as an internal or external command,

operable program or batch file.

 

C:\WINDOWS>

'xxxxxxxxxxxxxxxxxx' is not recognized as an internal or external command,

operable program or batch file.

 

C:\WINDOWS>

'xxxxxxxxxxxxxxxxxx' is not recognized as an internal or external command,

operable program or batch file.

 

C:\WINDOWS>

 

Maybe if you showed the form as the code seems to do what it should. Where does the form data come from?

 

 

HTH

Teamatomic

Link to comment
Share on other sites

it comes from the textarea on the main page. and is submitted by a javascript code.

 

The reason it was working properly was because it wasnt submitting the whole of the textarea.

 

if you do the same thing in the textarea the error message will stack up

 

EDIT: At mjdamato I have to use a textarea. your code just uses an input box.

as my javascript code grabs the messages from the .txt file, and places them as the value of the textarea

Link to comment
Share on other sites

EDIT: At mjdamato I have to use a textarea. your code just uses an input box.

as my javascript code grabs the messages from the .txt file, and places them as the value of the textarea

 

Oh really!? What is that first tag after the FORM tag?

  <form method="GET">
    <textarea name="text"><?php echo $text; ?></textarea>
    <input type="text" name="idx" value="<?php echo $idx; ?>">
    <button type="submit" name="submit">Submit</button>
  </form>

 

You didn't provide ALL of the relevant code for your project - so I winged it as best I could. The code I provided does work - at least how I interpreted your requirements. Did you even try the code I posted? It is a completely self-contained script that you can run. If it seems to work how you want, you can then repupose it with slight modifications to your exisitng code.

Link to comment
Share on other sites

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.