Rcon Sending Command to Server - php

I would like to send custom text by web to my game server throught this script, but i dunno how to define the text inside input
Any tip or suggestion or fix?
the script is:
<?php
function send_command($ip,$port,$rcon,$command) {
$fp = #fsockopen("udp://".$ip, $port, $errno, $errstr);
if ($fp){
$request = chr(1).chr(0).chr(242).chr(strlen($rcon)).$rcon.pack("S",strlen($command)).$command;
fwrite($fp, $request);
}
}
$name = "Owner";
echo "<input type='text' name='$msg'";
if (isset($_REQUEST['send'])) {
send_command("192.168.1.69",36963,"asdasd","say ©255255255".$name.": ".$msg);
}
?>
<html>
<form>
<input type="submit" value="send" name="send">
</form>
</html>
"Error "is:
Notice: Undefined variable: msg in D:\xampp\htdocs\test\index.php on line 11
Notice: Undefined variable: msg in D:\xampp\htdocs\test\index.php on line 14

Don't define your input's ID with a '$'. PHP interprets that as a variable. Name it 'msg'. You may then reference it with $_POST['msg'] or $_GET['msg'], depending on how you sent it to the PHP file.

Related

How to submit form data through VSCODE?

I'm having trouble submitting form data through VSCODE. So basically I have a nodejs program that runs on vscode and my goal is to submit some input data from that to a online form for example.
Run the program.js file in vscode
The file picks out a username field
Submits it to a online file through php
This is the HTML file & PHP file that writes input username data to data.txt
<!DOCTYPE html>
<html>
<BODY>
<form action = "submit.php" method="POST">
<p>
<input type = "text" name = "username" />
</p>
<input type = "submit" name="submit_btn" id = "submit" value = "Submit"/>
</form>
</BODY>
</html>
<?php
if(isset($_POST['submit_btn']))
{
$username = $_POST['username'];
$text = $username ."\n";
$fp = fopen('data.txt', 'a+');
if(fwrite($fp, $text)) {
echo 'saved';
}
fclose ($fp);
}
$lines = file("data.txt"); // Get the file as an array
$lines = array_unique($lines); // Merge all duplicate lines
// Save as a new file
$file = fopen("datacurated.txt", "w");
fwrite($file, implode("", $lines));
fclose($file);
?>
So the html file is not really important but I'm not so good at coding I was trying to send a post data request through vscode but didn't work.
I was wondering if it's possible to get rid of the html file and keep the php online and have it write the needed data. I need the delete duplicate text function in the php file as well.
Is this possible using AXIOS in vscode?
As the request package has been deprecated, install got instead.
Then your Node code:
(async () => {
const { body } = await got.post("https://www.website.com/submit.php", {
json: {
username: "Whatever..."
}
});
console.log(body);
})();
You don't care what www.website.com/submit.php is written in, but you have to be certain that that server will accept a Http Post request from your computer. It is trivial for them to obstruct what you are trying to do by filtering out your domain or by adding a Captcha.

PHP Post data not received

i'm currently working on a small script for my Homepage but i ran into a problem.
I Try to upload an Image, but it seems like the POST data from the form is not being received. What did i do wrong?
I already changed the post_max_size and everything in the php.ini.
These are the Errors i get:
"Notice: Undefined index: image in ...." & "Notice: Undefined index:
submit in ...."
<form method="POST" action="/eye/sites/handling/post.php" enctype="multipart/form-data">
<div class="fileUpload">
<span><i class="fa fa-folder-o" aria-hidden="true"></i> Bild wählen</span>
<input type="file" class="upload" name="image"/>
</div>
<input type="submit" value="Upload It!" name="submit"/>
</form>
<?php session_start();
error_reporting(E_ALL);
if (isset($_SESSION["login_stat"])) {
date_default_timezone_set('Europe/Berlin');
$config = "$_SERVER[DOCUMENT_ROOT]/eye/more/config.xml";
$xml = simplexml_load_file($config);
$picWidth = $xml->pic->width;
$picHeight = $xml->pic->height;
$fulldate = date('dmYHis');
if(isset($_POST["submit"])) {
if (file_exists($_FILES['image']['tmp_name']) || is_uploaded_file($_FILES['image']['tmp_name'])) {
$typeCheck = $_FILES['image']['type'];
if ($typeCheck != "image/jpeg") {
$error = "Not a .jpg";
header('location: /eye/sites/post.php?stat=bad&error='.$error);
exit;
}
$file = $_SERVER['DOCUMENT_ROOT']."/uploads/".$fulldate.".jpg";
$type = "image/jpeg";
move_uploaded_file($_FILES['image']['tmp_name'], $file);
$file_thmb = $_SERVER['DOCUMENT_ROOT']."/uploads/!1A_thmb/".$fulldate.".jpg";
include "resize-class.php";
$resizeObj = new resize($file);
$resizeObj->resizeImage($picWidth, $picHeight, 'crop');
$resizeObj->saveImage($file_thmb, 100);
// header('location: /eye/sites/post.php?stat=good');
} else{
// header('location: /eye/sites/post.php?stat=bad&error=No File');
}
} else{
// header('location: /eye/sites/post.php?stat=bad&error=No Data');
echo $_SERVER['CONTENT_TYPE'];
echo "<br>";
echo $_FILES['image']['tmp_name'];
echo "<br>";
echo $_POST['submit'];
echo "<br>";
}
} else {
header('location: /eye/index.php?stat=in');
}
?>
Edit:
The problem is definitely about my Localhost.
This whole thing is working fine on my Webspace, but on my localhost it's not working.
BUT: I'm not getting errors anymore, when is click on Submit it goes to the php file that should save the image, but nothing is happening. I just see a white Page.
But like i said, it runs perfectly on my webspace..
If this is running on your local machine, do a quick check to make sure your "php.ini" file is configured to allow file uploads.
php.ini
file_uploads = On
The codes look fine. Check if your form action is posting to the correct path and if I may suggest using a simpler approach to test your file upload function before making it more complex. Use the following to start testing.
if (isset($_POST["submit"])) {
if (file_exists($_FILES['image']['tmp_name']) || is_uploaded_file($_FILES['image']['tmp_name'])) {
echo "Upload is working!";
}
}
Keep us updated on your findings.
Perhaps this general information will help someone, as it helped me: a submitted form will only include fields that have defined 'name' attributes. 'id' is not enough.
The idea is that 'id' identifies an element in the DOM for use by JavaScript (either as a global variable or for use in document.getElementById(ID)), but 'name' identifies those elements whose names and values will be sent to the destination ('action') page.
So it makes sense that there are two different identifying attributes, used in two different ways.

Undefined variable submit at PHPMaker custome template

<?php
if (!isset($_POST['submit1'])==($submit == "Dig Gmail")){
if (!function_exists("ssh2_connect"))
die("function ssh2_connect doesn't exist");
$connection = ssh2_connect('x.x.x.x', 22);
ssh2_auth_password($connection, 'xxxx', 'xxxx');
$stream = ssh2_exec($connection, 'dig #127.0.0.1 gmail.com');
$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
if (stream_set_blocking($stream, true)) {
echo "<pre>";
echo "Output:".stream_get_contents($stream);
echo "</pre>";
} elseif (stream_set_blocking($errorStream, true)) {
echo "Error:".stream_get_contents($errorStream);
} else {
echo "No Output";
} fclose($errorStream);
fclose($stream);
}
?>
<form action="" method="post">
<input type="submit" class="btn btn-success"
name="submit1" value="Dig Gmail">
</form>
the message for error code is
Notice: Undefined variable: submit in C:\xampp\htdocs\coba\home.php on line 402
thanks for your advice
You are using POST variables from your form below, therefore you should use the $_POST array, containing the variables submitted from the from.
The above example would work in some older PHP versions with insecure registre_globals turned on (which is never a good idea). Also the name was wrong.
Modify the line
if (!isset($_POST['submit1'])==($submit == "Dig Gmail")){
to
if (!isset($_POST['submit1'])==($_POST['submit1'] == "Dig Gmail")){
and it should do the job for you.

"Notice: Undefined index: " message for the following code on localhost

I have written a code - It takes user input and displays sha1() string for the input.
I get the 'undefined index' notice on local host even after declaring the variables and using isset() function.
Notice: Undefined index: enc in C:\Program Files\EasyPHP-12.1\www\MySQL\localhost_drupal\encrypt.php on line 61
It works fine on the remote (production) server.
What is the fault in the following code?
<?php
//variable declaration
$enc = $len = "";
// checking with isset
if(isset($_POST['enc'])) {
//sha1()
$enc = sha1($_POST['enc']);
// strlen function
$len = strlen($_POST['enc']);
}
?>
//HTML
<!DOCTYPE html>
<html>
<head><title>Generate Password</title></head>
<body>
<form name = "encry" action = "encrypt.php" method = "post">
<input type = "text" name = "enc" >
<input type = "submit" value = "Submit">
</form>
//OUTPUT
<?php
//Line 61
echo "<p> You entered :" . $_POST['enc']."</p>";
echo "<p> Length of the string you entered :" . $len. "<p>";
echo "<p> Your Password is : ". $enc . "</p>";
?>
</body>
</html>
The reason being for the error is that your entire code is inside one page and errors out on initial load. Error reporting is set on one server, but isn't on the other.
You should be using isset() against a named submit button (which I have named) and around where you're using
echo "<p> You entered :" . $_POST['enc']."</p>"; etc..
Change your code to the following:
<?php
//variable declaration
$enc = $len = "";
// checking with isset
if(isset($_POST['enc'])) {
//sha1()
$enc = sha1($_POST['enc']);
// strlen function
$len = strlen($_POST['enc']);
}
?>
//HTML
<!DOCTYPE html>
<html>
<head><title>Generate Password</title></head>
<body>
<form name = "encry" action = "encrypt.php" method = "post">
<input type = "text" name = "enc" >
<input type = "submit" value = "Submit" name = "submit">
</form>
//OUTPUT
<?php
if(isset($_POST['submit'])) {
//Line 61
echo "<p> You entered :" . $_POST['enc']."</p>";
echo "<p> Length of the string you entered :" . $len. "<p>";
echo "<p> Your Password is : ". $enc . "</p>";
}
?>
</body>
</html>
To set error reporting on:
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
It's an E_NOTICE. Likely on production you suppress error messages (or at least notices). This is fine, but it does explain why it breaks in development.
Fix the issue and the notice will go away.

PHP echo values outside conditional if

I have the following PHP code:
<?php
//Connection to PDO Database
?>
<form method="post" action="">
<p>Busisness telephone 1</p><input id="business_telephone_01" name="business_telephone_01" tabindex="auto" value="<?php echo $result['business_telephone_01']; ?>" type="text" />
<input name="submit" type="submit" value="Save Changes"></form>
<?php
//Get from Form
if((empty($_POST['submit']) === false)){
$business_telephone_01 = $_POST['business_telephone_01'];
//Formating of telephone numbers
$message = 'This message I want to display';
echo 'This is another message';
}
echo $message;
//Code to update table through PDO
?>
Regardless of where I do the echo whether it is echo 'This is another message'; within the conditional brackets or _ echo $message;_ outside the brackets nothing is being echoed and no error is being displayed.
The html form and the PDO are working correctly and are being updated but nothing is being echoed. No error is being shown in the error log.
UPDATE:
If I use if((empty($_POST['submit']) === false)){ I get PHP
Notice: Undefined variable: hello
If I use if (isset($_POST['submit'])) { I get PHP Notice:
Undefined variable: hello
If I use if (!isset($_POST['submit']))
{ it gives me a list of undefined variables that I use e.g. from
my code above business_telephone_01
My full code
if((empty($_POST['submit']) === false)){
//Get from Form
$address_building_name = $_POST['address_building_name'];
$address_building_number = $_POST['address_building_number'];
$address_street = $_POST['address_street'];
$address_locality = $_POST['address_locality'];
$address_postcode = $_POST['address_postcode'];
$address_country = $_POST['address_country'];
//Formating of address
$address_building_number = strtoupper($address_building_number);
$address_building_number = str_replace(' ','',$address_building_number);
$address_building_name = ucwords($address_building_name);
$address_street = ucwords($address_street);
$address_locality = ucwords($address_locality);
$address_postcode = strtoupper($address_postcode);
$address_country = ucwords($address_country);
echo 'Hello';
$good = 'Good bye';
}
echo $good;
I'd be willing to bet $message isn't being echo'd because it's never initialized. (The if block, where it is supposed to be initialized, is not being executed because the conditional is failing.)
First off, you should use isset to determine if a POST variable has been submitted:
if (isset($_POST['submit'])) {
Or, to see if it has not been submitted:
if (!isset($_POST['submit'])) {
Secondly, you should enable error reporting on your program and let us know what errors (if any) you are getting:
error_reporting(E_ALL);
ini_set("display_errors", 1);
You can add these two lines to the very top of your script, right after the opening <?php line, which should help shed some light on the situation.
The problem could be that the $message variable is never set within your if statement.
If the 'if' condition is not matched, then $message is never set and you will not be able to echo the value.
To test, you could set the $message variable to some value before you start your if statement.
$message = 'condition failed';
if(isset($_POST['submit'])){
....
$message = 'This message I want to display';
}
echo $message;
If the condition is met, it will echo "This message I want to display".
If the condition fails, it will echo 'condition failed';
A quick dirty test, but it will tell you if the $message variable will be initialized inside your 'if' statement.

Categories