Reputation: 17
I have a question concerning variables. Imagine I have a php scripts that shows error messages depending on the the header (www.example.com?error=1). This would show the error message 1. Now how could I do this without having a variable in the header? I mean using Post instead of Get. How can I "send" a post variable to another script without using a form?
Thanks, phpheini
PS: The reason why I wanna do is that I dont want people to change the variable in the url (from 1 to 2 to 3 and so on).
Upvotes: 0
Views: 222
Reputation: 2824
I found this PHP and CURL script from here:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/path/to/form");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
'foo' => 'foo foo foo',
'bar' => 'bar bar bar',
'baz' => 'baz baz baz'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
?>
I have not tested this, but it should work.
Upvotes: 1
Reputation: 14959
The quick answer is you can use html forms to transfer your data using POST method.
PHP just receive the data sent by the browser and the only method to force the post sending is by using forms.
You can use hidden forms spiced with javascript or similar to mimic the link but it is painful to me.
You can also use ajax to transfer the data but there is not a true way to stop the user tampering your datas. It is just a sligthly more difficult. With Firefox and firebug, for example, tampering POSTed variables is a breeze.
Maybe you want to think about changing the loginc behind your application and test the error messages on server side based on real data. If you use a link that leads to an error message, maybe, you can avoid to show it, for example.
Upvotes: 0
Reputation: 1219
You must use cURL to send POST data to other pages. However, this is irrelevant for the kind of thing you want to do. What's the problem with GET? Using either GET or POST, you must always filter user input.
Upvotes: 0