Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending POST data without form

Can i send for example a string or another piece of information to another .php file without it being exposed [thus not by GET but by POST conform to what i know] without using a form?

like image 309
Samuel Avatar asked Sep 23 '10 17:09

Samuel


People also ask

How to get data without form in JavaScript?

When you put the data in URL you can either use $_GET or $_REQUEST to get the data. In case you want to get the data using the $_POST method, you need to pass is using the post method itself. In case you are using JQuery.

When to use POST vs get?

Use GET if you want to read data without changing state, and use POST if you want to update state on the server.

How do I send a post request in HTML?

To post HTML form data to the server in URL-encoded format, you need to make an HTTP POST request to the server and provide the HTML form data in the body of the POST message. You also need to specify the data type using the Content-Type: application/x-www-form-urlencoded request header.


2 Answers

If you don't want your data to be seen by the user, use a PHP session.

Data in a post request is still accessible (and manipulable) by the user.

Checkout this tutorial on PHP Sessions.

like image 123
Stephen Holiday Avatar answered Oct 11 '22 12:10

Stephen Holiday


You could use AJAX to send a POST request if you don't want forms.

Using jquery $.post method it is pretty simple:

$.post('/foo.php', { key1: 'value1', key2: 'value2' }, function(result) {     alert('successfully posted key1=value1&key2=value2 to foo.php'); }); 
like image 40
Darin Dimitrov Avatar answered Oct 11 '22 13:10

Darin Dimitrov