Author Topic: How to read $_POST data in a module  (Read 15206 times)

0 Members and 2 Guests are viewing this topic.

Offline
*
How to read $_POST data in a module
« on: April 12, 2017, 03:05:50 PM »
I am trying to create a module that takes input from the user by way of a form. The form is submitted to the same module (ie index.php?module=mymodule) which then processes the input data.

However, when I try to read the $_POST data, all I get is an empty array - how do I access the $_POSTed data, please ?

Thanks

Offline
*
Re: How to read $_POST data in a module
« Reply #1 on: April 13, 2017, 04:33:58 AM »
then you probably have something wrong in your script

check that your from starts with something like this
Code: [Select]
<form action='' method= 'post'>
AntiDDoS Protection (web + mail)
http://centos-webpanel.com/website-ddos-protection-proxy

Join our Development Team and get paid !
http://centos-webpanel.com/develope-modules-for-cwp


Services Monitoring & RBL Monitoring
http://centos-webpanel.com/services-monitor


Do you need Fast and FREE Support included for your CWP linux server?
http://centos-webpanel.com/noc-partner-list
Installation Instructions
http://centos-webpanel.com/installation-instructions
Get Fast Support Here
http://centos-webpanel.com/support-services

Offline
***
Re: How to read $_POST data in a module
« Reply #2 on: April 13, 2017, 05:34:04 AM »
Try like this to see what`s going on:
This is just an example, change your ['username'] with whatever you use:
This is your form(let`s say):
Code: [Select]
<form action="index.php?module=mymod" method="post">
        Username:                          <input type="text" name="username" value="John"><br>
<center><button class="button" type="submit" name="submit">Add Container</button></center>
</form>
$_POST['username'] is name="username", so whatever you put inside name="" have to be it.
Now check it like this.
Code: [Select]
if (isset($_POST['username'])) { $user = $_POST['username']; } else { $user = "No data"; }
echo $user;
If you get "No data" when you test it, please contact me for more help.
UNIX is a very simple OS, but you have to be a GENIUS to understand it ...

Offline
*
Re: How to read $_POST data in a module
« Reply #3 on: April 14, 2017, 05:58:32 AM »
Thanks for the replies.

I was working on a (client) module that lists all .zip and .tgz files in the users folders. The user selects the file they want to decompress (using radio buttons) and the script decompresses the file (I had read that individuals were having problems with the permissions of decompressed files). However when the form was submitted, and I tested the $_POST variable, it was coming up with an empty array.

I guess I'd been doing something wrong with the form variables.

I got around the problem by switching to $_GET as I only wanted to pass a single filepath back to the script. It's a bit 'cluncky', but it does the job . . .

. . . except because I'm using the shell to extract the files, the permissions are all messed up  >:(

Thank goodness for the 'Fix Permission' button in the admin Panel.

Thanks for taking the time to reply, though - at least I know that I can use $_POSTed data.

Offline
***
Re: How to read $_POST data in a module
« Reply #4 on: April 21, 2017, 02:00:00 PM »
Actually using $_GET to send data to shell for execution is like to give to everybody full root access and to tell them "Please log in to my shell and write 'rm -rf /'." This is not a security risk, this is insane. Doesn`t matter if you are the only one who uses this script. If it`s public visible, some crawler bots will find it and from there ... hope you don`t have important info on that server.
Now I`m a bit busy to write more, but if you contact me here on PM or mail me at root@born2host.com I`ll try my best to help you fix this.
UNIX is a very simple OS, but you have to be a GENIUS to understand it ...